On Sep 28, 6:30 am, puzzlecracker <ironsel2...@gmail.com> wrote:
> The statement is taken from FAQ [24.2]. What about non-virtual
> functions? Can they be overriden? I still don't see a good
> justification to prefer private inheritance over composition. In
> fact, I have never seen it in a commercial code. If someone did,
> please share the use-case and decisions behind it.
>
> Thanks
I think it's fair to say that there's nothing that can be done with
private inheritance that can't be done with aggregation/composition.
The usual justification is that you want to aggregate a class and
override some virtual methods that it provides. Consider a class that
will use a timer. The timer has a virtual method OnTick which is
called every n seconds as defined in the class.
You could derive a class and override the OnTick method to do
something specific for your class and then aggregate that derivation.
Or, you could inherit privately and override OnTick within your class
giving you slightly/arguably cleaner code.