vineoff wrote:
When to do like this:
class A { ... };
class B : private A { ... };
Infrequently. Unlike public inheritance, which indicates an "Is-a"
relationship, private inheritance indicates a "Is-Implemented-With"
relationship. But you can usually use composition instead of private
inheritance to accomplish that:
class B {
A a_;
public:
B();
};
There are always exceptions, of course. If A has virtual functions
that need to be overridden, some would advise having B inherit
privately from A and override those virtual functions. Others would
advise creating a new class, C, that inherits publicly from A and
overrides A's virtual functions, then having class B use composition to
include C:
class A {
virtual void func();
public:
~A();
};
class C : public A {
void func();
};
class B {
C c_;
};
Best regards,
Tom