Final classes and structs

suggest change

The final specifier, added in C++11, forbids deriving from a class or struct. A final class:

class A final {
};

Now any attempt to subclass it will cause a compilation error:

// Compilation error: cannot derive from final class:
class B : public A {
};

A final class may appear anywhere in a class hierarchy:

class A {
};

// OK.
class B final : public A {
};

// Compilation error: cannot derive from final class B.
class C : public B {
};

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents