Search This Blog

Sunday, November 15, 2009

C++, Seal Your Base Class, non-inheritable

Like the keyword seal on class in c#, in C++ we can just make the base class' constructor private. This way the derive class cannot instantiate itself because it has to call base's (the inaccessible) constructor first.

So how do we construct the base class this way? Simply provides a static function which calls the private constructor.

Note: keyword private provides the notion of accessibility, not visibility.

No comments: