Reputation: 1101
I get it how to access data from inner class, when we are talking about that same class. But lets say we have a class called "ben", and other one is "bob". Now "bob" has inner private class called "john" and in john, there is his phone number variable. I would like to access johns phone number form class ben.
I hope I explained it at least "okay". So, is it possible to do this, or should I just make a getter method for bob class?
Upvotes: 0
Views: 97
Reputation: 1099
If you want to access john from ben, it means that john should not be private to bob. The whole point of making john private to ben is to hide it from others.
So to solve your problem, make john a normal class since it is needed by more than one class.
Upvotes: 2
Reputation: 10333
john has to declare that ben is his friend or ben can't have his phone number
class ben {
string john() { return bob::john::phone; }
};
class bob {
class john
{
friend class ben;
static string phone;
};
};
Upvotes: 0