我正在尝试使用友元函数重载 << 运算符,但由于某种原因它没有看到私有成员变量。任何为什么会发生这种情况的想法都会很有帮助。
这是头文件
class Set
{
private:
struct Node
{
int val;
Node* link;
};
Node *cons(int x, Node *p);
Node *list;
public:
Set() {list = NULL;}
bool isEmpty() const;
int size() const;
bool member (int x) const;
bool insert (int x);
bool remove (int x);
void print() const;
const Set operator+(const Set &otherSet)const;
const Set operator*(const Set &otherSet)const;
Node* getSet()const{return list;}
void setList(Node *list);
friend ostream& operator <<(ostream& outputStream, const Set &set);
};
这是函数定义。
ostream& operator <<(ostream& outputStream, const Set &set)
{
Node *p;
p = list;
outputStream << '{';
while(p->link != NULL)
{
outputStream << p->val;
p = p->link;
}
outputStream << '}';
return outputStream;
}