less than 1 minute read

整理自 C++ Primer, 5th Edition


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.

Tags:

Categories:

Updated:

Comments