Prevent class inheritance in C++

As of C++11, you can add the final keyword to your class, eg

class CBase final
{
...

The main reason I can see for wanting to do this (and the reason I came looking for this question) is to mark a class as non subclassable so you can safely use a non-virtual destructor and avoid a vtable altogether.

Leave a Comment