Рассмотрим следующий пример:Как класс друга может получить доступ к частному члену вложенного класса?
class SIP{
public:
friend std::ostream& operator<<(std::ostream& os, const SIP& c);
private:
class BusStop;
std::vector<BusStop*> mbusStops;
};
class SIP::BusStop{
private:
struct BusInfo;
std::vector<BusInfo*> mbusStopTerminal;
};
struct SIP::BusStop::BusInfo{
std::string from;
std::string to;
};
std::ostream& operator<<(std::ostream &os, const SIP &c) {
for (std::vector<SIP::BusStop*>::const_iterator it = c.mbusStops.begin();
it != c.mbusStops.end(); it++){
for (std::vector<SIP::BusStop::BusInfo*>::const_iterator it2 = mbusStopTerminal.begin();
it2 != mbusStopTerminal.end(); it2++){
}
}
return os;
}
Это не будет компилировать, потому что структура BusInfo является частным. Классы друзей не могут получить доступ к закрытым членам вложенных классов по умолчанию. Что я должен делать в этой ситуации? Есть ли обходной путь?