I read an answer some time back to a question regarding dynamic_cast. The dynamic_cast failed to work because the base class had no virtual methods. One of the answers said that deriving from classes with no virtual methods generally means a bad design. Is this correct? Even without taking advantage of polymorphism, I still can’t see the wrongness in doing this.
I read an answer some time back to a question regarding dynamic_cast. The dynamic_cast
Share
It depends what we’re talking about:
std::unary_functioncomes to mind)privateinheritance (used instead of composition to benefit from Empty Base Optimization) it’s fine tooThe problem comes when you starts treating such a Derived object polymorphically wrt this Base class. If you ever attain such a position, then it’s definite code smell.
Note: Even when noted as fine above, you are still providing the ability to use the class polymorphically, and you thus expose yourself to subtle bugs.