C++: final

Yao Yao on May 15, 2015

Preventing Inheritance

Under the new standard, we can prevent a class from being used as a base by following the class name with final:

class NoDerived final { /* */ };	// NoDerived can't be a base class

class Base { /* */ };
class Last final : Base { /* */ };	// Last can't be a base class


Preventing Overriding

We can also designate a function as final. Any attempt to override a function that has been defined as final will be flagged as an error.

blog comments powered by Disqus