类的 friend 函数无法访问其私有向量;
friend function of the class can't access to its private vector;
我有以下声明:
friend ostream& operator<<(ostream&,const List&);
我有以下定义:
ostream& operator<<(ostream& out,const List& item) {
vector<List::Employee>::const_iterator It;
for (It=item.employees.begin();It!=item.employees.end();It++) {}
}
员工是
我自己的结构,员工是班级列表中员工的私人载体。编译器给了我以下错误:
std::vector<List::Employee,std::allocator<List::Employee>> List::employees is private
有什么想法如何解决吗?
friend 声明应该在 List 类定义中。
class List{
...
friend ostream& operator<<(ostream&,const List&);
};
相关文章:
- 尝试通过多个向量访问变量时,向量下标超出范围
- C++从另一个类访问公共静态向量的正确方法是什么
- 访问存储在向量C++中的结构的多态成员
- 如何从静态向量访问类元素?
- 在类 A 中创建类型为 B 类的向量 - 访问数据 [C++] [成员在两个类中都是私有的]
- 从父类的向量访问子类函数,而无需向下转换
- 如何使用常数向量访问成员函数
- 如何从C 向量访问单个单词
- 从C++中传递给函数的指针向量访问矩阵
- 多向量访问与本地对象
- C 迭代器与用于向量访问的指针
- 从向量访问成员功能
- 如何在 c++ 中从 "pointer-to-objects" 向量访问对象
- 如何从双精度向量的向量访问数据
- 从指针向量访问成员函数?C++
- 如何使用SWIG Python从内部向量访问c ++对象方法
- 无法从向量访问对象的getter
- 从向量访问某些类函数C++的问题
- 从基类类型的向量访问派生类方法
- 从对象指针向量访问对象