Re: lists by James
James
Tue Dec 16 16:28:49 CST 2003
At this point, in this thread, THREE people have now post code in an
attempt to solve this man's problem, and NONE OF THEM have actually made the
destructor virtual. (You at least point out that you code is wrong, but it
would be nice if you also included the correct code.....)
struct Obj
{
/*code omitted*/
Obj* pNextOne;
virtual ~Obj() {} // nothing needed in body for the code shown. No
changes needed elsewhere.
}
--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
"Douglas Peterson" <Tergiver@nospam.msn.com> wrote in message
news:uEhgbQ0wDHA.1196@TK2MSFTNGP12.phx.gbl...
> class Base
> {
> char* b1;
> ~Base()
> {
> delete b1;
> }
> };
>
> class Derived : public Base
> {
> char* d1;
> ~Derived()
> {
> delete d1;
> }
> };
>
> Derived * pd = new Derived;
> delete pd;
>
> In the above case, both d1 and b1 get deleted in the destructors.
>
> Base * pb = new Derived; // notice the base type pointer
> delete pb;
>
> In above case, only b1 gets deleted as the destructor for Derived is not
> called.
> If the Base destructor had been declared as virtual, than both destructors
> get called regardless of which type is used to delete the object.
>
>
> "Kyle" <anonymous@discussions.microsoft.com> wrote in message
> news:023c01c3c33a$b0ca3ff0$a301280a@phx.gbl...
> > >-----Original Message-----
> > >Hi,
> > >use a virtual destructor.
> > >
> > >Lucas/
> >
> > But what, does it do ... I mean ive added one, but it's of
> > no use, perhaps i dont understand sth (im getting other
> > error though :),
> > Am i supposed to make a destructor in a child object,
> > which will delete additional variables ???
> > My list is deleted in a destructor of another class -
> > Manager. Ive tried almost everything (i think) - i mean
> > lots of casting (ive included variable in base object
> > which identifies the type of object, then i cast the
> > object to its (proper)type (child or base) and delete it,
>
>