Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!sun-barr!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: Virtual functions and missing constructors Message-ID: <9346@alice.UUCP> Date: 11 May 89 14:13:06 GMT References: <583@hrc63.co.uk> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 38 In article <583@hrc63.co.uk>, andrew@hrc63.co.uk (Andrew Haylett "Baddow") writes: The problem you describe appears to be an unplanned feature in your compiler. class A { public: A() { }; A(int z) { }; virtual void f() { cout << "a\n"; }; }; class B : public A { public: B() { }; // B(int z) { }; // This constructor is missing void f() { cout << "b\n"; }; }; main() { A a (1); // instance of A, one argument B b1 ; // instance of B, calls B's constructor B b2(1); // instance of B, calls A's constructor Bug #1 -- B doesn't have a B::B(int) constructor, so the compiler should reject this call. Constructors are not inherited. a.f(); // says "a" b1.f(); // says "b" b2.f(); // says "a" -- WRONG -- should be "b" Bug #2. b2 is a B, not an A, and should say so. } -- --Andrew Koenig ark@europa.att.com