0

Hi I have this error in the main.cpp with my operator= and I don't know what's the problem with it. Or maybe the problem is from the functions... I don't know. If you could help me it will be great! Thank you!

my 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;
}

my operator= (in 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;
    }

my operator in the header:

List& operator=(List&);
Elish
  • 61
  • 5
  • 2
    You need to make the RHS a `const&`. `List& List::operator=(List const& l){`. See [What are the basic rules and idioms for operator overloading?](https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading) – R Sahu May 12 '20 at 20:11
  • How are you compiling the files? – GoodDeeds May 12 '20 at 20:12
  • great it worked!! thank you! – Elish May 12 '20 at 20:25

0 Answers0