Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will the compiler-generated destructor of an abstract base class be virtual?

class Base
{
    virtual void foo() = 0;
    //~Base();     <-- No destructor!
};

Obviously, Base will be derived. So, does C++ says the compiler-generated destructor of Base must be virtual?

Thanks!

like image 813
Julien-L Avatar asked Aug 12 '11 14:08

Julien-L


1 Answers

No, the destructor will not be virtual unless you mark it as such. The reason is simple - calls can be made virtually both via pointers and via references and how and whether you make calls virtually is unrelated to whether you create objects with new. If you don't create objects with new you don't have to delete them and so you don't need virtual destructors.

like image 171
sharptooth Avatar answered Sep 18 '22 02:09

sharptooth