Consider the following class:
class X {
};
One can easily inherit from this:
class Y : public X {
};
Okay so far... Let's say we don't want anyone to inherit from Y
we can then do this instead.
class Y sealed : public X {
};
Or we could do this:
class Y final : public X
};
What are the main differences between the two keywords final
and sealed
? I know their basic purposes and what they are used for; I just wanted to know if there was anything specifically different between the two.
sealed
is not Standard C++ - it appears to be a Visual C++ CX extension. From that same page:
The ISO C++11 Standard language has the
final
keyword, which is supported in Visual Studio. Usefinal
on standard classes, andsealed
on ref classes.