[comp.lang.c++] initializing 1 field in array of classes

williamt@athena1.Sun.COM (William A. Turnbow) (03/27/90)

	Have a general C++ programming question.

	I currently have a structure with one member, pid, being a pointer
to an integer.  I have an array of X of these structures.  I have need
of these pid's being in shared memory.

	To accomplish this, I am allocating a block of X*sizeof(int) in
shared memory, the going through the array of structs and setting the
pointers to the X ints in shared memory.

	I am converting this to a class.  The question comes up on how
to initialize all of these pointers at the same time.  Note that it
is not a good solution to allocate X separate shared memory segments
of size 'int' each.  I only want to have to allocate 1 shared memory
segment for the entire array.  

	It seems that a member function is not the best way to go here, but
that a friend function that is passed the pointer to the beginning of
the array would be (which could then allocate 1 segment of shared memory
and init all X pointers at the same time).  This also has the advantage
that only X would have to know about the shared memory segment.  

	Comments?

-wat-

   --- An it harm none, do what you will.