C++ 无法从好友类访问成员

C++ 无法从好友类访问成员,c++,class,friend,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

我有这样的声明

#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
}
有趣的是,如果我使用备用友元声明(它显式地指定了方法),它会工作吗?有没有想过为什么他们会不同


使用英特尔C++编译器111.065 BTW.< /P> < P> < <代码> >代码> T/<代码> > <代码> P**t** PaseWrase>代码> .< /P> < p> <您的小<代码> t>代码>应是<代码> > **** * * > />代码>也许你需要添加一个转发声明。我在评论中看到了一个细微的拼写错误,请注意PTPathWriter中大写的T。可能性有多大?汉斯,把这个评论变成一个答案,这样我就可以把它标记为接受!!!我现在觉得自己有多蠢:)+1对汉斯来说就像鹰一样的眼睛。PtPathWriter是在PtPathLeg之前声明的吗?也许你需要添加一个转发声明。我在评论中看到了一个细微的拼写错误,请注意PTPathWriter中大写的T。可能性有多大?汉斯,把这个评论变成一个答案,这样我就可以把它标记为接受!!!我现在觉得自己有多蠢:)+1对汉斯来说就像鹰一样的眼睛。

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);