27
Private inheritance VS composition.
I'm having a little confusion when to use each. Since private inheritance seals, in a way, the chain on inheritance, given:
class A
{
private:
int z;
protected:
int y;
public:
int x;
};
class B : private A
{
/* B's data members and methods */
/* B has access only to A's public and protected */
};
class C : public B
{
/* can access no fields of B */
};
C won't be able to use any of B's fields. When would I use private inheritance, and when would I use composition?
thanks!