How do you Access base variable from class outside the hierarchy?
How do you access a variable from a base class outside the class hierarchy?
example:
Code:
class Base
{
...
int x;
}
class Sub : public Base
{
...
void method1(Sub* sub); //this method can pass it self
//to a method2 in class wantsToAccessX
}
class wantsToAccessX
{
...
void method2(Sub* sub) //method that looks at variable x
}
Now the variable x is accessable from class Sub, but i cant figure out how to access x from the other class wantsToAccessX. Have tried things like sub.x and sub->x.
It the only way to do this with a getterMethod in class Sub?