【发布时间】:2015-06-04 05:43:08
【问题描述】:
Set.h 文件包含在公共类中:
friend const Set operator +(const Set & a, const Set & b);
Set.cpp 文件包含一个名为:
const Set Set::operator +(const Set & a, const Set & b)
为什么会出现这个错误:'const Set Set::operator+(const Set&, const Set&)' must take either zero or one argument'
-编辑-
正如你们中的几个建议的那样,删除我的 .h 文件前面的朋友会导致另外两个错误
Set.h:23:53: 错误:'const Set Set::operator+(const Set&, const Set&)' 必须采用零或一个参数 const Set 运算符 +(const Set & a, const Set & b);
Set.cpp:73:55: 错误:'const Set Set::operator+(const Set&, const Set&)' 必须采用零或一个参数 const Set Set::operator +(const Set & a, const Set & b){
-编辑2-
const Set operator +(const Set & a, const Set & b){
Node * intersection;
while(a != nullptr && b != nullptr){
if(a->value < b->value){
intersection -> value = a;
intersecioon = intersection->next;
a=a->next;
}
if(a->value > b->value){
intersection -> value = b;
intersecioon = intersection->next;
b=b->next;
}
}
while(a != nullptr){
intersection -> value = a;
intersecioon = intersection->next;
a=a->next;
}
while(b != nullptr){
intersection -> value = b;
intersecioon = intersection->next;
b=b->next;
}
return intersection;
}
这是我的操作员函数。
【问题讨论】:
-
不要删除
friend,从第二行删除Set::,即在cpp文件中,定义为const Set operator+(const Set & a, const Set & b)。如果仍有问题,请发布 MCVE stackoverflow.com/help/mcve -
更多错误,添加功能了解更多详情
标签: c++ linked-list operator-overloading overloading