C++ Inheritance & composition used together
问题 I have class A, having methods that update properties of B. So, I need inheritance. class B{ public: int x; }; class A : public B{ public: void update(int y){ x = y; } }; I also want to reach function "update" through class B, so I also need composition. class B{ public: A a; int x; }; class A : public B{ public: void update(int y){ x = y; } }; I want my structure as such, so that I want to track properties of objects-type Bs this way: ... B.a.update(5); int n = B.x; However, I cannot use