he keywords final
in Java and C# respectively ensure that a certain class shall not be subclassed. C++ doesn't have a similar keyword. Naive programmers are often tempted to derive from classes such as std::string
, which clearly weren't meant to be used as base classes. These illicit derivations can cause undefined behavior. Find out how to implement a compile-time constraint that blocks subclassingplus, a technique for blocking object copying.
How can you disable inheritance from a class that isn't meant to be derived from? How do you prevent the copying of objects that aren't meant to be copied?
Restrict the access of your special member functions.