gpt4 book ai didi

c++ - 无法从好友类访问成员

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:02:16 26 4
gpt4 key购买 nike

我有这样的声明

#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。

最佳答案

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

关于c++ - 无法从好友类访问成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2964654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com