Date: Wed, 18 Mar 1998 10:01:11 +0200 (EET) From: Andris Pavenis To: Noam Rotem cc: Andris Pavenis , djgpp AT delorie DOT com Subject: Re: Run-time error: pure virtual function called In-Reply-To: <350ECEB1.BFDE2CD0@johnbryce.co.il> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Tue, 17 Mar 1998, Noam Rotem wrote: > > Andris Pavenis wrote: > > > On Mon, 16 Mar 1998, Gavin Sinclair wrote: > > > > > the message "Pure virtual function called" (using DJGPP of course, gcc > > > 2.7.2.1). > > > > The most obvious way how to get this message is to call virtual function > > from constructor or destructor of base class when this virtual function is > > redefined in inheritted class > > Why is this a runtime error? Can't the compiler locate this bug? > This is in base class. Compiler may not know that function is redefined. Here is an example that can give this error. It was more difficult to reproduce this bug as I expected. Direct call to virtual function from destructor of base class give linker error. However indirect call trough other member function may be not detected by compiler: class A { public: A() {} virtual ~A(); int tttt (void); virtual int someFunct (void) = 0; }; class B : public A { public: B() : A() {} virtual ~B(); virtual int someFunct (void); }; int main (void) { B test; } A::~A() { this->tttt (); } /* Wrong!!! call to function that uses virtual */ /* function */ int B::someFunct () { return 0; } B::~B() {} int A::tttt (void) { return someFunct(); } Andris Pavenis