Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!sunybcs!boulder!chase From: chase@boulder.Colorado.EDU (Chase Turner) Newsgroups: comp.lang.c++ Subject: constructors and instantiation Message-ID: <2575@sigi.Colorado.EDU> Date: Wed, 14-Oct-87 22:51:20 EDT Article-I.D.: sigi.2575 Posted: Wed Oct 14 22:51:20 1987 Date-Received: Fri, 16-Oct-87 07:17:07 EDT Sender: news@sigi.Colorado.EDU Reply-To: chase@boulder.Colorado.EDU (Chase Turner) Distribution: na Organization: University of Colorado, Boulder Lines: 73 This message was submitted two weeks ago; there have not been any replies yet. I am re-submitting the question to determine the following: a) am I violating the sprit of instantiation? b) I want to instantiate objects in shared memory which is accessable to seperate processes (environment : sun workstations, 4.3 unix) -- I do not want a function call *new* which provides an object space in local memory which would then have to be copied to a shared memory area. (and, the local memory reference would have to be deleted since I do not want the object there....) Is the constructor the appropiate mechanism? c) why is the value of *this* not updated in the main body to reflect the assignment of the object to the malloc space I created? Any reply would be appreciated. Thanks in advance. Chase. ---------old message below------------------------------ I am having difficulty utilizing the Free Store example (8.5.8, pg 280 of The C++ Programming Language). Specifically, I need to instantiate objects within shared memory; for the purposes of this example, I will utilize a malloc instead of the call shmget (). Within the constructor, I re-assign the value of "this" but the update value is ignored. In fact, I assumed that the constructor would over-ride the instantiation of the object "ts" in the main body, but the c code generated by the CC pre-compilier indicates that a local structure is created prior to the call to the constructor. The following is a run-time example..... value is 11, address is 142912 // within the constructor value is 10, address is 251657776 // after returning from constructor The following is the program...... #include #include #include class stamp { int val; public: stamp (int); void print_myself (); }; stamp::stamp (int v) { val = v; //val should not exist since I have not made a call //to new or reserved the space for the object. //obviously it does exist. Is there an implicit //call to new? Should I override new with another //function? How can new be 'intercepted'? this = (stamp*) malloc (sizeof (stamp)); val = v+1; print_myself (); } void stamp::print_myself () { printf(" value is %d, address is %d \n",val,&val); } main() { stamp ts (10); ts.print_myself (); }