Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!helios.ee.lbl.gov!pasteur!wenti!brianl From: brianl@wenti.Berkeley.EDU (Brian Lee) Newsgroups: comp.lang.c++ Subject: Correction to Re: Default constructor, unexpected call Keywords: constructor Message-ID: <26655@pasteur.Berkeley.EDU> Date: 1 Aug 90 19:21:00 GMT Sender: news@pasteur.Berkeley.EDU Reply-To: brianl@wenti.Berkeley.EDU (Brian Lee) Lines: 56 X-Local-Date: 1 Aug 90 12:21:00 PDT 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. :-) In my example, the default constructors for superclasses are called because my specification of the subclass copy constructor replaces the default component-wise initialization that would have been generated and by omission of explicit base initialization specifies that the default constructors should be used. For example, the classes class X { public: X() { cout << "default X::X()\n"; } X(const X&) { cout << "copy X::X(const X&)\n"; } }; class Y : public X { public: Y() { cout << "default Y::Y()\n"; } // Y(const Y&) { cout << "copy Y::Y(const Y&)\n"; } }; class Z : public Y { public: Z() { cout << "default Z::Z()\n"; } Z(const Z&) { cout << "copy Z::Z(const Z&)\n"; } }; should really have been defined as class X { public: X() { cout << "default X::X()\n"; } X(const X&) { cout << "copy X::X(const X&)\n"; } }; class Y : public X { public: Y() { cout << "default Y::Y()\n"; } // Y(const Y& y) : X(y) { cout << "copy Y::Y(const Y&)\n"; } }; class Z : public Y { public: Z() { cout << "default Z::Z()\n"; } Z(const Z& z) : Y(z) { cout << "copy Z::Z(const Z&)\n"; } }; The revised definitions work fine. Sorry for any confusion this may have caused. Brian Lee