Reputation: 29
could someone explain me this kind of "inheritance" which can be found in class Y: private?
class X
{
private: char c_;
public: X(char c) : c_(c){}
};
class Y
{
private: X x_; // What is this ?
public: Y(X x): x_(x){}
};
int main()
{
X m('a');
Y *test = new Y(m);
delete test;
return 0;
}
Upvotes: 0
Views: 56
Reputation: 595377
This is not inheritance, as Y
does not derive from X
.
This is just simple encapsulation. X x
is just a member variable of Y
, no different than char c_
being a member variable of X
.
Upvotes: 1