C++ supports protected
inheritance: A class can derive from a base class B
in a way that the "outside" world doesn't see that class "as a B
" but the class itself and it's derived classes does see itself "as a B
".
struct B {};
struct Klass : protected B {
// here I am B
};
struct Derived : public Klass {
// here I am B
};
// ...
Klass k; // k is not a B
Derived d; // d is not a B
(Demo)
Is there any use to this language feature? I'm specifically looking for patterns / functionality which is easy to implement with protected inheritance, but difficult (or "ugly", verbose) without it.
Similar to this question, but none of the answers there really apply here IMO. Interest sparked by this stackoverflow question.