class MainClass
{
friendclass Base;
protected:
int x;
public:
MainClass(int x)
{
this->x=x;
}
// ...
};
class Base
{
public:
MainClass *mc;
// ...
};
class Other:public Base
{
public:
Other(MainClass *mainclass) {mc=mainclass;}
int get_x()
{
return mc->x;
}
};
int main()
{
MainClass mc(112);
Other ot(&mc);
std::cout<<ot.get_x();
}
What I get is
error: 'int MainClass::x' is protected within this context: [...]
I want to make that Other could access MainClass::x. I know that I could simply add friendclass Other; to Mainclass but maybe it's possible to avoid this?