简体   繁体   English

会员无法通过朋友班访问

[英]Member is inaccessible from friend class

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得到一个错误说

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. 使用Intel C ++编译器11.1.065 btw。

您的小t应该是P**t**PathWriter的大写T

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (朋友类的)成员“Node::next”不可访问 - member "Node::next" (of a friend class) is inaccessible C++:成员不可访问 - 使用朋友 function 允许一个 class 修改另一个 ZA2F2ED4F8EBC2CBB4ZC2A 成员数据 - C++: Member is inaccessible - using friend function to allow one class to modify another class member data 操作符重载(使用binaray好友函数)类没有成员,并且成员不可访问 - operator overloading(using binaray friend function) class has no member, and member inaccessible 即使该类已声明为友元类,数据成员也无法访问 - data member is inaccessible even though the class has been declared as friend class 类数据成员无法访问 - Class Data Member Inaccessible 从朋友班访问私人成员 - access private member from a friend class 为什么从模板方法无法访问此类自己的受保护成员? - Why is this class's own protected member inaccessible from a template method? 尝试重载&lt;&lt; stream as friend?时无法访问成员函数? - Inaccessible member function when trying to overload << stream as friend? 从另一个类访问类成员,最好使用指针或朋友吗? - Accessing class member from another class, is it better to use pointer or friend? C ++从好友类访问成员函数 - C++ access member-function from friend class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM