Re: My final shape program, what do you think?

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 03/17/04


Date: Tue, 16 Mar 2004 23:11:55 -0000


"John Cho" <johncho@johncho.us> wrote in message
news:Xns94AE983F587C2spockieverizonnet@199.45.49.11...
>
> > Shape needs a virtual destructor
> >
> > virtual ~Shape() {}
> >
>
> >> delete shapearray[count];
> >
> > This is undefined behaviour, because of the lack of a virtual
> > destructor. The rule in C++ is that if an object is deleted though a
> > pointer to its base class then the base class must have a virtual
> > destructor or its undefined behaviour.
>
>
> my derive classes do not have destructors orignally, so i should not
> have to use a virtual deconstructor
>

That's not true.

>
>
> i should have to use a virtual deconstructor if i want dervive
> deconstructors to be called before base deconstructors
>
>
> however, none of my classes have deconstructors, hence no need for
> virtual deconstructors

That's not true. The C++ rule is exactly as I said

"The rule in C++ is that if an object is deleted though a
pointer to its base class then the base class must have a virtual
destructor or it is undefined behaviour."

If you don't want to believe me then fine, but the rule is like I said.

john



Relevant Pages

  • Re: My final shape program, what do you think?
    ... >> pointer to its base class then the base class must have a virtual ... >> destructor or its undefined behaviour. ... > i should have to use a virtual deconstructor if i want dervive ...
    (alt.comp.lang.learn.c-cpp)
  • Re: My final shape program, what do you think?
    ... >> pointer to its base class then the base class must have a virtual ... >> destructor or its undefined behaviour. ... > i should have to use a virtual deconstructor if i want dervive ...
    (comp.lang.cpp)
  • Re: My final shape program, what do you think?
    ... >> pointer to its base class then the base class must have a virtual ... >> destructor or its undefined behaviour. ... > i should have to use a virtual deconstructor if i want dervive ...
    (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 ... 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)