Overloading+运算符必须采用无参数链表或单参数链表
Overloadig + operator must take either no or single argument linklist
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&)"必须采用零或一个参数"
-编辑-
正如你们几个人所建议的,删除我的.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::运算符+(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;
}
这是我的操作员功能。
根据Set.h
中的声明,operator+
是Set
的非成员友元函数。在Set.cpp
中,您试图将其定义为定义成员函数。正确的定义应该有这样的签名:
const Set operator +(const Set & a, const Set & b)
只需从.cpp
文件的定义中删除Set::
。
头文件将operator+
声明为非成员函数,因此没有理由在声明中以Set::
作为前缀。这将是定义类类型Set
的成员函数所必需的。
相关文章:
- 反向给定链表中的K节点
- 如果没有malloc,链表实现将失败
- 文本文件中的单词链表
- 努力将整数转换为链表。不知道我在这里做错了什么
- 链表,反向函数,数据结构
- 使用std::list创建循环链表
- 链表的泛型函数remove()与成员函数remove)
- 为什么不能修改对象中的值?另外,我如何改进此链表?
- 我们可以删除链表中静态内存中的节点吗
- C++,指针数组,指向双链表中的条目
- 链表中写入访问冲突的未知原因
- 如何修复链表类实现的未处理异常0xDDDDDDDD
- 打印所有链表的元素 (C++)
- C++:如何做一个链表,结构作为参数传递?
- 如何在没有参数的情况下实现返回双向链表大小的函数?int size() const.
- C++添加到包含 char[] 作为参数的链表中
- Overloading+运算符必须采用无参数链表或单参数链表
- 弄清楚链表的插入函数参数
- 键函数的链表插入被某些参数卡住了
- 使用c++引用参数在链表中分配新节点