Code: class x{int a;}; class y:public x{}; main(){y k; k.a=3; } How can I access "k.a"? PS: You can't change or omit any part of the code. a have to be private. Member access specifier have to be public ( class y::public x ). You can add functions to x class but you can't add data members to x class. You can add functions to y class too. -> Maybe we need to type a friend function.
Add a public get and set function to x, which will be inherited by y: Code: class x { private: int a; public: int get_a() { return a; } void set_a(int new_a) { a=new_a; } };