Re: Polymorphism without virtual in C++
On Aug 6, 7:40 pm, Joe Greer <jgr...@doubletake.com> wrote:
Victor Bazarov <v.Abaza...@comAcast.net> wrote in news:g7cmb5$6so$1
@news.datemas.de:
{
base1 *o = new my;
delete o;
Ka-boom! Undefined behaviour.
Not necessarily Ka-boom, you might get nasal demons instead.
Seriously though, the problem is that if you add any member
variables to your derived class, Base' destructor won't know
how to clean them up and will probably only return a fraction
of the memory to the heap.
The problem here is that it is undefined behavior, and that
anything can happen. I can't think of a reasonalble
implementation where only part of the memory is freed, but I can
certainly think of cases where it will corrupt the free space
arena, and cause the program to crash, either immediately, or
sometime later.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34