Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!csd4.milw.wisc.edu!dogie.macc.wisc.edu!indri!nero!blake!uw-beaver!ssc-vax!dmg From: dmg@ssc-vax.UUCP (David Geary) Newsgroups: comp.lang.c++ Subject: Constructors and new Message-ID: <2684@ssc-vax.UUCP> Date: 30 May 89 22:10:40 GMT Organization: Boeing Aerospace Corp., Seattle WA Lines: 43 According to BS, section 5.5.7, a constructor for a class can determine whether it was called by new or not. "If it is called by new, the pointer this has the value zero at entry, otherwise this points to space already allocated for the object..." Ok, so what does the following print? #include class testclass { public: testclass() { if(this == 0) puts("Used new..."); else puts("Did not use new..."); } ~testclass() { puts("I'm a destructor..."); } }; main() { testclass var; new testclass; } Output: Did not use new... Did not use new... I'm a destructor... This tells me one of two things: 1) I've found a bug in the compiler. 2) I don't know what the h*ll I'm doing. My ego tells me #1, but my experience tells me it has to be #2 ;-) -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ David Geary, Boeing Aerospace, Seattle ~ ~ "I wish I lived where it *only* rains 364 days a year" ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~