Private inheritance
-
What do you need a private access writer if all base class fields are inaccessible?
-
It is in order that all members of the base class are not available outside ( only available from the interior of the class or from friends of the class).
The inheritance is not much different from the aggregation, and
class A : private B { ... };
similarclass A { private: B b; };
♪Onelike
private: B b;
in successionB
may be summoned as members of their class, i.e. notb.f()
♪f()
♪It is also possible to inherit from the abstract class and redesign its methods without showing all these cases outside, for example:
struct Callback { virtual void done() = 0; };
void run(Callback* b);
class Cls : private Callback {
public:
void some() {
run(this);
}
private:
void done() override { ... }
};