Can someone help me get this started? I need to write a program that concatenates two linked lists. I am getting some interesting errors.
It is defined in my header like so:
List<T>& operator+(const List<T>&)const;
It is energized below like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
template<typename T>
List<T>& List<T>::operator+(const List<T> & rhs)const
{
List<T> left = new List<T>;
List<T> right = new List<T>;
left = this;
right = rhs;
//For testing purposes
cout << "L: " << left << endl;
cout << "R: " << right << endl;
}
That's all I have so far. I get this error:
1>C:\Users\dumpledork\Desktop\List\ListTestMain.cpp(27): error C2679: binary '+' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
1> c:\users\dumpledork\desktop\list\List.h(16): could be 'List<T> &List<T>::operator +(const List<T> &) const'
1> with
1> [
1> T=char
1> ]
1> while trying to match the argument list '(List<T>, int)'
1> with
1> [
1> T=char
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This last line is the first error (List<char> l3 = l1 + 12;). The second error references the first snippet of code that I posted above, the header declaration.
If I return a list obj, the error doesn't change. I was thinking the error was in my header or on line 2.
Whats confusing to me is that it says cannot find operand of type 'int'. I am working with chars in this case, and I thought that it shouldnt matter whether I'm passing chars or ints because I have it templated.