This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/6006: problem with pure virtual functions and destructord wrote:
> Hi
> Is there a particular reason why a a virtual function called
> in a destructor is the function of this class and not the derived class?
because the standard says so.

> (There are implementations of C++ where the virtual
> function of the derived class is called)
those implementations are buggy.

> In my example, however, the function g() calls the pure virtual
> function f(). But g() can be called from the destructor of A,
> without causing a problem.
neither call 'works'. Drat, someone's borrowed my c++ std, so this is
from memory. in the dtor of A, the B object is not complete (B's
dtor has been executed, modulo the bits pertaining to its bases).
We shouldn't call (non-static) member functions of B, because
there's no constructed B object for their this pointer to point to.
The std says, that in this case, virtual functions dispatch to the
function seen in the definition of the base being ctor'd or dtor'd
(i.e. what the final overrider would be if that base was the complete

IIRC, calling a pure virtual function is undefined, so anything can
happen. g++ 3.0 reports abstract virtual `virtual void A::f()' called from destructor
because it can prove that that resolved to a pure virtual. It cannot
do so for the one embedded in g, but if you executed such a program
it would fail.


Dr Nathan Sidwell :: Computer Science Department :: Bristol University
           The voices in my head told me to say this

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]