我重载了赋值运算符“=”
但不知道哪里错了
错误如下:operator = must be a <Unknown> member
struct FileNode
{
char NAME[10];
int NUM;
FileNode *next;
};
int operator =(FileNode &a, FileNode &b)
{ //错误提示指示这行
for(int i=0; i<10; i++)
{
a.NAME[i] = b.NAME[i];
}
//a.next = b.next;
a.NUM = b.NUM;
return 0;
}
赋值运算符“=”必须作为类的成员函数
c++规定一下四个必须重载为成员函数
= [] -> ()
是啊,不是成员函数,就是重载了也用不上啊,
具体一点 就是
struct FileNode
{
char NAME[10];
int NUM;
FileNode *next;
FileNode& operator =(FileNode& a)
{
for(int i=0; i<10; i++)
{
NAME[i] = a.NAME[i];
}
next = a.next;
a.NUM = a.NUM;
return *this;
}
};