This is my code:
class Base
{
friend class SubClass;
int n;
virtual int getN()
{
return n;
}
};
class SubClass: public Base
{
public:
SubClass() {}
SubClass(const SubClass& s) {}
};
int _tmain(int argc, _TCHAR* argv[])
{
SubClass s;
int x = s.getN();
return 0;
}
error C2248: 'Base::getN' : cannot access private member declared in class 'Base'
What more do I have to do to access my private members from Base ?
Your
frienddeclaration means thatSubClassgets to access it in the scope ofSubClass.If you want users of a class to access something, at some point you need to a write
public:function:You can write a using declaration to bring a base class function into the current class: