Your mileage may vary ...
The tough answer will be that non-public inheritance is futile.
Personally, I use it in either of two cases:
- I would like to initiate an empty base optimization, if possible (usually in the template code with predicates passed as parameters)
- I would like to override the
virtual function in the class
In both cases, I use private inheritance this way, because inheritance itself is an implementation detail.
I saw people using private inheritance more liberally and almost systematically instead of composition when writing wrappers or expanding behavior. C ++ does not provide a “simple” delegate syntax, so you can write using Base::method; to immediately provide a method instead of writing the correct call forwarding (and all its overloads). I would say that this is a bad form, although it saves time.
Matthieu M.
source share