假设我已经定义了这两个类:
class Node
{
friend class list;
public:
Node (const int = 0);
Node (const Node &);
private:
int val;
Node * next;
Node & operator= (const Node &);
};
class list
{
public:
list ();
list (const list &);
~list ();
list & operator+= (const Node &);
Node & operator[] (const int) const;
private:
list & delete_Node (const int);
Node * first;
int length;
};
然后,在一个main.cpp
文件中,我有这些行:
list l1;
l1 += 1;
l1 += 41;
l1[1] = 999; // <-- not permitted: Node::operator= is private
Node::operator=
我的问题是:当且仅当左值是列表中的引用(它是 的朋友类)时,是否可以授予访问权限,Node
即使main()
它不是朋友函数?