www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/18/03:11:23

Date: Wed, 18 Mar 1998 10:01:11 +0200 (EET)
From: Andris Pavenis <pavenis AT latnet DOT lv>
To: Noam Rotem <nrotem AT johnbryce DOT co DOT il>
cc: Andris Pavenis <pavenis AT latnet DOT lv>, djgpp AT delorie DOT com
Subject: Re: Run-time error: pure virtual function called
In-Reply-To: <350ECEB1.BFDE2CD0@johnbryce.co.il>
Message-ID: <Pine.GSO.3.96.980318093926.13517A-100000@sisenis>
MIME-Version: 1.0


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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019