c++ - 错误 c++ 没有可行的重载 '=' ,我的 operator= 有问题
问题描述
嗨,我的 operator= 在 main.cpp 中有这个错误,我不知道它有什么问题。或者问题可能出在功能上……我不知道。如果你能帮助我,那就太好了!谢谢!
我的 main.cpp:
#include <iostream>
#include "List.h"
using namespace std;
List merge(List &lst1, List &lst2);
void makeSet(List lst);
int main()
{
List lst1, lst2, mergedList;
cout<<"enter sorted values for the first list:"<< endl;
cin>>lst1;
cout<<"enter sorted values for the second list:"<< endl;
cin>>lst2;
mergedList = merge(lst1,lst2); //My ERROR is here (No viable overloaded '=')
cout <<"the new merged list: " << mergedList <<endl;
makeSet(mergedList);
cout<<"the new merged set: " << mergedList << endl;
return 0;
}
我的操作员=(在 List.cpp 中):
List& List::operator=(List& l){
l.clear();
Link *src, *trg;
head = new Link(l.head->value, NULL);
src = l.head;
trg = head;
while(src->next!=NULL)
{
//create new Link, and attach to end of new list
trg->next = new Link((src->next)->value, NULL);
src = src->next;
trg = trg->next;
}
return *this;
}
标题中的我的运算符:
List& operator=(List&);
解决方案
推荐阅读
- reactjs - 对象作为 React 子项无效 - 无法解决错误
- docker - 使用 Dockerized NGINX 反向代理到 Dockerized REST API
- c# - NpgsqlConnection 和 OpenAsync() 方法导致 NullReferenceExeption
- c# - c#读取不同计算机操作系统和语言上的文本文件目录
- r - 通过R中的列号访问数据框中的变量?
- python - Django 表单:电话字段未显示
- c++ - 当给定要删除的节点的值时,如何从链表中删除节点
- c - 在指针之间进行算术运算的正确方法
- xpath - 如何在 Xquery 函数 (BaseX) 中将字符串转换为 Xpath
- spring-integration - Spring响应式文件集成