In the previous post I’ve discussed the C++11
final keyword and how it can be used.
I also gave a guideline that you shouldn’t use
final on non-polymorphic classes.
My reasoning was as follows:
For some classes - like policy classes or any other class where you might want to have the EBO - making them
finalcan be harmful.
For other classes - those which aren’t used polymorphically -
finalis unnecessary. Every (good) C++ developer is taught early on that you shouldn’t use a class in a polymorphic inheritance hierarchy if it doesn’t have any
Publicinheritance there makes no sense and is harmful. Everybody knows that, the
finalis just there to enforce it.
There are only little use cases for
finalin polymorphic hierarchies. So in general you don’t need it.
This has spawned a discussion both on reddit and in the blog comments, so I decided to write this follow-up to unify the discussion and write about each argument.» read more »