From: wemccaug AT prairienet DOT org (Wendy E. McCaughrin) Newsgroups: comp.os.msdos.djgpp Subject: no copy-ctor for temps Lines: 34 Message-ID: Date: Fri, 01 Oct 1999 19:45:14 GMT NNTP-Posting-Host: 192.17.3.4 X-Complaints-To: newsmgr AT prairienet DOT org X-Trace: firefly 938807114 192.17.3.4 (Fri, 01 Oct 1999 14:45:14 CDT) NNTP-Posting-Date: Fri, 01 Oct 1999 14:45:14 CDT Organization: Prairienet -- Your Community Network for East Central Illinois To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com The following example shows that 'gxx' will not invoke a copy-ctor for temporaries, only for variables. #include #include class Overflow { char mssg[80]; public: Overflow( char* ccp ) { strcpy(mssg,ccp); } Overflow( const Overflow& ovfl ) // must be 'const' ! { cerr << "copy ctor: "; strcpy(mssg,ovfl.mssg); } void Report() { cerr << mssg; } }; void TstCpy( Overflow ); // call by value int main() { Overflow of = " I am a variable\n"; TstCpy(of); // passing a variable: copy-ctor invoked TstCpy(Overflow(" I am a temporary\n")); // passing temp: no copy-ctor return 0; } void TstCpy(Overflow ovrflw) { ovrflw.Report(); } When compiled and run, the output is: copy ctor: I am a variable (indicating call of copy-ctor) I am a temporary (defaults to bit-wise copy)