会员无法从朋友班访问

时间:2010-06-03 09:28:05

标签: c++ class friend

我有这样的声明

#include "Output/PtPathWriter.h"
// class PtPathWriter // I've also tried forward declaring the friend class

// leg data is a class designed to hold data for a single leg.
class PtPathLeg
{
    friend class PtPathWriter; // doesn't work
    //friend void PTPathWriter::writeToFile(string fileName, PtPath* path); // works

protected:
    vector<map<int, shared_ptr<BoardingStopAlternative>>> m_boarding_stop_alternatives; 
    // some other stuff
}

但是我收到来自PtPathWriter的错误

PtPathWriter.cpp(44): error #308: member "PtPathLeg::m_boarding_stop_alternatives" (declared at line 79 of "../include/Paths/PtPathLeg.h") is inaccessible
1> path->m_leg_data.at(legnr).m_boarding_stop_alternatives.at(stopId);

有趣的是,如果我使用备用好友声明(明确指定方法),它确实有用吗?他们为什么不同的任何想法?

使用英特尔C ++编译器11.1.065 btw。

1 个答案:

答案 0 :(得分:0)

您的小t应该是T中的首都P**t**PathWriter