我试图使用朋友函数超载< <运算符,但它由于某种原因没有看到私有成员变量。任何想法为什么会发生这将是相当有益的。朋友函数不能看到私有成员变量
这里的头文件
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;
}
'friend ostream&Set :: operator <<'? –