Search code examples
c++abstract-classdestructorcompiler-generated

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!


Solution

  • 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.