Thread: destructors and parameters + pointers to classes questions.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Having several destructors using polymorphisms and that way still having the "standard" destructor which would be the one used for automatic calls?
    When a derived class is constructed, first the constructor of the base class runs, then the constructor of the derived class.

    When a derived class is destructed, first the destructor of the derived class runs, then the base class is destructed.

    When you have a polymorphic object (pointer to base), the destructor of base must be virtual, otherwise only the base destructor is called, but not the destructor of derived class.

    That is, you don't pick which parts of a derived class will be destructed and which not. You'll need to destruct the whole object and several destructor calls happen for that.
    Last edited by anon; 12-30-2007 at 07:25 PM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed