In C++ classes, how can I access a super-set's variable from within another sub-set? This can only be shown visually as an example for you to understand.
The CIA is above the President and have the right to keep confidential information from the President.
class CIA {
public:
bool aliensExist = true; // 100%
};
class President {
public:
bool doAliensExist() {
return aliensExist; // Not sure, no access to CIA's aliensExist variable
}
};
class Subset : public President, public CIA {
};
int main() {
Subset subset;
cout << "Aliens exist = " << subset.doAliensExist() << endl;
}
How can I access aliensExist
using the method inside President
class from within the Subset
class?
I know the example above is illogical and of course President
cannot access CIA
without it being a direct subset of it, but I'm wondering what's a good approach for something like this?