3 ms·
This is indeed perverse. Could someone explain why the solution isn't rather to not define default parameters for the args in the parent class? It makes more se
by Y_Y 3y ago
This is indeed perverse. Could someone explain why the solution isn't rather to not define default parameters for the args in the parent class? It makes more sense to me, as someone who doesn't even know the 10% of cpp required to claim mastery.
- cjfd 3y agoWhen compiling some code that uses this inheritance hierarchy you might only have access to the source code of the parent class and create child classes via factory functions that return a pointer to the base class. If the parent class does not contain the default parameter values, you have no way of knowing them.
- GuB-42 3y agoIn this case you won't have default parameters at all when calling through a base class pointer, resulting in an error if you don't mention the parameter explicitly. It won't solve the problem, but it is a much saner behavior. If you want the expected behavior, that is that a call through a base class pointer uses the default parameters of the derived class, then you shouldn't use default parameters at all. Use overloading instead.
- twic 3y agoOr make the default some sort of sentinel, and resolve it to a real default in the method.