On May 13, 12:04 am, xavier <xavier> wrote:
> > class Base
> > {
> > public:
> > virtual ~Base() {}
> > };
> > class Derived : public Base
> > {};
> > int main()
> > {
> > Base* p =3D new Derived(); // static type of p is "pointer to Base"
> > // dynamic type of p is "pointer to
Derived"
> > }
> in the above example, what will happen if we add 'delete p;'
> at the end of main(). What will be deleted ? Only the base
> class part or both base and derived part of instantied object
> ?
Objects are deleted, not parts of objects. Either the code has
undefined behavior (and anything can happen), or delete will
delete the entire object. (In this case, of course, it is the
lattern.)
--
James Kanze (GABI Software) email:james.kanze@[EMAIL PROTECTED]
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


|