Re: inhibit compiler warning C4624 for a class hierarchy



Ben Voigt <rbv@xxxxxxxxxxxxx> wrote:
Every instance will be
freed by the base class destructor and operator delete, regardless of
specific type.

It doesn't work this way. Any class must have a destructor before you
can create (or, to be exact, destroy) an instance of it. It could be
trivial, it could be private, it could be implicitly defined, but a
class must have one. From the standard:

12.4/5 An implicitly-declared destructor is implicitly defined when it
is used to destroy an object of its class type (3.7). A program is
ill-formed if the class for which a destructor is implicitly defined
has:
....
- a base class with an inaccessible destructor.

The moment you use delete on the pointer of the derived type (whether in
the base class or otherwise) your program becomes ill-formed.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Virtual destructors are unique virtuals right
    ... The destructor of a derived class does not call the ... >> of its base class, regardless of whether the base class has a virtual ... constructor for the BaseClass, then calls the constructor for the ... DerivedClass. ...
    (comp.lang.cpp)
  • Re: Odd behavior, vector member, MFC and consol app
    ... someone call the base class destructor which then ended up doing something bad. ... it should have no virtual functions at all. ... A good clue that a class is not intended for derivation is the absence ...
    (microsoft.public.vc.mfc)
  • Re: Cant compile this code *****SOLVED****
    ... your real program might contain hundreds of code sequences ... that the base class implements a 'virtual' ... destructor, so that when de-allocating objects created via ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Virtual destructors are unique virtuals right
    ... The destructor of a derived class does not call the ... >> of its base class, regardless of whether the base class has a virtual ... The derived class destructor always calls the base class ...
    (comp.lang.cpp)
  • Re: inhibit compiler warning C4624 for a class hierarchy
    ... Any class must have a destructor before you can ... create (or, to be exact, destroy) an instance of it. ... implicitly-declared destructor, ... a base class with an inaccessible destructor. ...
    (microsoft.public.vc.language)

Loading