I have been trying to overload the equal (==) and less than (<) operators for a linked sorted list. I am not sure if I understand exactly if what I am doing makes sense. I have a struct with a string variable for DestinationCity, of which these operators have to compare. I have used strcmp in an attempt to make it work. Here is the code:
bool sortedListClass::operator <(const flightRec& rhs) const{
if (strcmp(flightRec.DestinationCity, rhs.DestinationCity) < 0)
{ // I'm not sure if flightRec.DestionationCity is what I should write.
return true;
}
else
return false;
}
bool sortedListClass::operator ==(const flightRec& rhs) const{
if (strcmp(flightRec.DestinationCity, rhs.DestinationCity) == 0)
{
return true;
}
else
return false;
}
Here are the error messages.
sortedListClass.cpp: In member function ‘bool sortedListClass::operator<(const flightRec&) const’: sortedListClass.cpp:185:25: error: expected primary-expression before ‘.’ token
sortedListClass.cpp: In member function ‘bool sortedListClass::operator==(const flightRec&) const’: sortedListClass.cpp:194:28: error: expected primary-expression before ‘.’ token