This is the mail archive of the gcc-bugs@gcc.gnu.org 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


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?
(There are implementations of C++ where the virtual
function of the derived class is called)

Anyway, the gnu implementation of c++ does not match (section 12.7 para3)
>     [section 12.7 para 3]
>     ... When a virtual function is called directly or indirectly
>     from a constructor (including from the mem-initializer for a
>     data member) or from a destructor, and the object to which
>     the call applies is the object under construction or destruction,
>     the function called is the one defined in the constructor or
>     destructor's own class or in one of its base, but not a function
>     overriding it in a class derived from the constructor or
>     destructor's class, or overriding it in one of the other
>     base classes of the most derived object (1.8).
> 
This paragraph states that if the virtual function is called
directly OR INDIRECTLY from a constructor or destructor, then
the virtual function of the class itself is called.

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.

Thanks 
  Jody Weissmann
  Computer Science Department
  University of Zurich
  Winterthurerstr 190
  8057 Zurich
  Switzerland
  Phone: +41(0)1 635 43 17
  EMail: jody@ifi.unizh.ch


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