Title: What am I doing wrong here? Several "no match for operator" errors in my compile
Tags: c++
Question: These seem to be my only errors. From my understanding, I only needed to overload an operator if I was setting "sortedListClass" equal to another declared "sortedListClass" or if I was asking if they were less than, equal to, not equal to, etc.. but these are user declared... not declared "sortedListClasses" so im confused.. can anyone shed light on these compilation errors? Thanks!
I'll include all of the code I have incase any of it has significance to the errors...
Basically I am dealing with linked lists with structs and pointers..
here is my list.h:
#ifndef LIST_H
#define LIST_H
struct cities
string city;
typedef cities listItemType;
typedef struct Node* nodePtr;
struct Node
listItemType data;
nodePtr next;
#endif
here is my sortedListClass.h :
#include <iostream&gt;
#include <fstream&gt;
using namespace std;
#include "list.h"
#ifndef sortedList_Class
#define sortedList_Class
class sortedListClass
private:
int size;
nodePtr Head;
public:
//Constructors and Destructor
sortedListClass();
sortedListClass(const sortedListClass&amp; L);
~sortedListClass();
//List operations
void ListInsert(listItemType NewItem);
void ListDelete();
void RetrieveCity();
void PrintList();
int ListLength() const;
bool ListIsEmpty() const;
}; //End Class
#endif
and here is my sortedListClass.cpp :
//Sorted List Class
//Contains function definitions for actions towards the cities Linked List
#include "sortedListClass.h"
#include <iostream&gt;
#include <cstdlib&gt;
#include <string&gt;
sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0sortedListClass()
size = 0;
Head = NULL;
sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0sortedListClass(const sortedListClass&amp; List)
if(List.Head == NULL)
Head = NULL;
else
Head = new Node;
Head-&gt;data = List.Head-&gt;data;
nodePtr NewPtr = Head;
for(nodePtr OrigPtr = List.Head -&gt; next; OrigPtr != NULL; OrigPtr = OrigPtr-&gt; next)
{
NewPtr-&gt; next = new Node;
NewPtr = NewPtr -&gt; next;
NewPtr -&gt; data = OrigPtr -&gt; data;
}
NewPtr -&gt; next = NULL;
sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0~sortedListClass()
bool success;
while(!ListIsEmpty())
ListDelete();
bool sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ListIsEmpty() const
return bool( size == 0);
int sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ListLength() const
return size;
void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0RetrieveCity()
string city;
bool success;
cout <<"Input a city name: ";
cin &gt;&gt; city;
cout << endl;
nodePtr cur = Head;
while(cur != NULL)
if(cur-&gt;data == city)
{
cout <<"This city is found" << endl;
success = true;
}
cur = cur-&gt;next;
if(!success)
cout <<"This city is not served" << endl;
void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0PrintList()
nodePtr cur = Head;
cout << "Number of cities: " << size << endl;
while(cur!= NULL)
cout <<cur-&gt;data;
cur = cur-&gt;next;
void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ListInsert(listItemType Item)
nodePtr newNode = new Node;
newNode -&gt; data = Item;
newNode-&gt;next = NULL;
if(Head = NULL)
Head = newNode;
else if (Item < Head-&gt;data)
newNode-&gt;next = Head;
Head = newNode;
nodePtr curr = Head, prev = Head;
while((newNode-&gt;data &gt; curr-&gt;data) &amp;&amp; (curr != NULL))
prev = curr;
curr = curr -&gt; next;
if(curr-&gt;next == NULL)
curr-&gt;next = newNode;
newNode-&gt;next = NULL;
else if(curr-&gt;data &gt; newNode-&gt;data)
newNode-&gt;next = curr;
prev-&gt;next = newNode;
void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ListDelete()
bool success = false;
string city;
cout << "Enter a city name to delete from the list: " << endl;
cin &gt;&gt; city;
nodePtr p = new Node;
nodePtr curr, prev;
curr = Head;
prev = Head;
p -&gt; data = city;
p -&gt; next = NULL;
if(Head == NULL)
cout <<"Unable to delete anything, list is empty." << endl;
else
while(curr-&gt;next != NULL)
{
if(curr -&gt; data == p -&gt; data)
{
prev-&gt;next = curr-&gt;next;
curr-&gt;next = NULL;
delete curr;
curr = NULL;
success = true;
}
else
prev = curr;
curr = curr-&gt;next;
}
if(!success)
cout <<"This city does not exist. Deletion cannot be performed." << endl;
and here is the errors I am getting...
sortedListClass.cpp: In member function ‘void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0RetrieveCity()’:
sortedListClass.cpp:63: error: no match for ‘operator==’ in ‘cur-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data == city’
sortedListClass.cpp: In member function ‘void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0PrintList()’:
sortedListClass.cpp:81: error: no match for ‘operator<<’ in ‘st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0cout << cur-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data’
/usr/include/c++/4.4/ostream:108: note: candidates are: st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; (*)(st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:117: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ios<_CharT, _Traits&gt;&amp; (*)(st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ios<_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:127: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ios_base&amp; (*)(st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ios_base&amp;)) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:165: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(long int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:169: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(long unsigned int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:173: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(bool) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/bits/ostream.tcc:91: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(short int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:180: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(short unsigned int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/bits/ostream.tcc:105: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:191: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(unsigned int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:200: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(long long int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:204: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(long long unsigned int) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:209: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(double) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:213: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(float) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:221: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(long double) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/ostream:225: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(const void*) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
/usr/include/c++/4.4/bits/ostream.tcc:119: note:                 st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;&amp; st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_ostream<_CharT, _Traits&gt;75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator<<(st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0basic_streambuf<_CharT, _Traits&gt;*) [with _CharT = char, _Traits = st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0char_traits<char&gt;]
sortedListClass.cpp: In member function ‘void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ListInsert(listItemType)’:
sortedListClass.cpp:93: error: no match for ‘operator<’ in ‘Item < ((sortedListClass*)this)-&gt;sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Head-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data’
sortedListClass.cpp:100: error: no match for ‘operator&gt;’ in ‘newNode-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data &gt; curr-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data’
sortedListClass.cpp:111: error: no match for ‘operator&gt;’ in ‘curr-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data &gt; newNode-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data’
sortedListClass.cpp: In member function ‘void sortedListClass75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ListDelete()’:
sortedListClass.cpp:128: error: no match for ‘operator=’ in ‘p-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data = city’
list.h:5: note: candidates are: cities&amp; cities75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0operator=(const cities&amp;)
sortedListClass.cpp:136: error: no match for ‘operator==’ in ‘curr-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data == p-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data’
[1]+  Done                    scite sortedListClass.cpp
Comment: I think a find a bug in the function `ListInsert` at line 4. Do you realy mean `if(Head = NULL)Head = newNode;` instead of `if(Head == NULL)Head = newNode;`?

Comment: Making a [testcase](http://sscce.org) is your first debugging step, not posting to the internet. :)


Here is another answer: I only needed to overload an operator if I was setting "sortedListClass" equal to another declared "sortedListClass" or if I was asking if they were less than, equal to, not equal to, etc
You're doing those things with listItemType, and never created any operators for it.
See how it's complaining about expressions such as ‘cur-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data == city’? The left-hand side has type listItemType, and the right-hand side has type st75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0string. The compiler has no idea what you want it to do with those two things.
Similarly:
error: no match for ‘operator&gt;’ in ‘newNode-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data &gt; curr-&gt;No75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0data’
Both sides of that expression have type listItemType. You need to define operator&gt; for that type.
I realise that the error output is verbose and complex, but all the information you need is in there somewhere!

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:04/07/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c++>', 'Title': 'What am I doing wrong here? Several "no match for operator" errors in my compile', 'ViewCount': 1129, 'id': 15869179, 'user_AboutMe': '', 'user_AccountId': 2518904.0, 'user_DisplayName': 'Volman2014', 'user_Reputation': 81.0, 'user_Views': 42.0, 'user_id': 2189647.0}}