Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!sci.kun.nl!atcmpe!leo From: leo@atcmp.nl (Leo Willems) Newsgroups: comp.lang.c++ Subject: Re: Correction to Re: Default constructor, unexpected call Message-ID: <643@atcmpe.atcmp.nl> Date: 2 Aug 90 19:39:03 GMT References: <26655@pasteur.Berkeley.EDU> Organization: AT Computing, Nijmegen, The Netherlands Lines: 61 From article <26655@pasteur.Berkeley.EDU>, by brianl@wenti.Berkeley.EDU (Brian Lee): > Many thanks to Brian Kennedy for kindly > pointing out that my example in Article 8944 really does produce > correct results. This is just another example of a computer doing > what you told it to do instead of what you wanted it to do. :-) > That may be, but your answer and the replay from Brain Kennedy have taken away the focus from my original problem. Since everybody seems to be on the beach these days, here it is again. My question is simple: why does the following program generate a call to the default constructor from class A for variable 'copd'? (If this is not a bug in 2.1 (2.0 as well) try switching the declarations of a and b in class C; then A::A() is not called: if the previous one is NOT a bug then this one is!) ============ #include class A{ public: A() { ida = 0; puts("default constructor A()"); } A(int i) {ida = i; puts("constructor A(int)"); } private: int ida; }; class B{ public: B() { idb = 0; puts("default constructor B()"); } B(B& b) { idb = b.idb; puts("copy constructor B(B&)"); } private: int idb; }; class C{ public: C(){ puts("default constructor C()");} protected: A a; //switch these: bug(?) gone B b; // if not a bug: A::A() gone!!!! }; main() { puts(" first a 'default' constructor:"); C defd; puts("\n now the copy constructor: "); C copd(defd); //suspicious A::A() class here } ======== Thanks in advance Leo