Search code examples
c++virtual-destructor

Destructor of a concrete class


Guideline #4 link text, states:

A base class destructor should be either public and virtual, or protected and nonvirtual.

Probably I'm missing something, but what if I just create a concrete class, that is not designed to be used as base class.

Should I declare it's destructor public and virtual? By this I'm implicitly declate that my class is "ready to be used as base class", while this is not necessary true.


Solution

  • The link text specifically says"A base class destructor should be"...

    The guidelines are only meant for a class which is designed to be used as a base class. If you are making a single, concrete class that will not be used as a base class, you should leave the public constructor non-virtual.