Is it possible to access the public member of the base class from an instance of the derived class in some other places in the program.
class base { public: int x; base(int xx){ x = xx; } }; class derived : base { public: derived(int xx) : base(xx){ } }; class main { public: derived * myDerived; void m1(){ myDerived = new derived(5); m2(myDerived); } void m2(derived * myDerived){ printf("%i", myDerived->x); } };
After the above code, I got the following error.
`error: 'int base::x' is inaccessible`
source share