无法从好友班级访问成员
我有一个像这样的声明
#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。
I have a declaration like this
#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
}
However I get an error from PtPathWriter saying
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);
Interestingly, if I use the alternate friend declaration (which specifies the method explicitly) it does work? Any thoughts on why they are different?
Using Intel C++ Compiler 11.1.065 btw.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的小
t
应该是P**t**PathWriter
中的大写T
。Your little
t
should be a capitalT
inP**t**PathWriter
.