I'm fairly new to C++ programming. I currently have an error C2678: binary '==': no operator found which takes a left-hand operand of type 'const Employee'
This error is point to line
if (*iLoc == aID)
I believe I am suppose to create a
bool Employee::operator==(const Employee & rhs) const
{
}
that will override the error. I think I need to make a overloaded ==
operator that is able to compare and unsigned int
to an Employee
object. But I am stuck. I was wondering if anyone is able to help. Part of my main.cpp is included.
bool Employee::operator==(const Employee & rhs) const
{
}
void searchItem(const List<Employee>& l1)
{
if (l1.size() == 0)
cout << "List empty!\n";
else
{
unsigned int ID;
cout << "Enter ID#: ";
cin >> ID;
size_t index = 0;
List<Employee>::const_iterator iLoc = l1.begin();
while (iLoc != l1.end())
{
if (*iLoc == aID)
{
cout << "Employee's Name: " << aID << " found at node # " << index << endl;
break;
}
index++;
iLoc++;
}
if (iLoc == l1.end())
cout << "ID# " << aID << " not found!\n";
}
}
void removeItem(List<Employee>& l1)
{
if (l1.size() == 0)
cout << "List empty!\n";
else
{
unsigned int aID;
cout << "Enter ID#: ";
cin >> aID;
size_t index = 0;
List<Employee>::iterator iLoc = l1.begin();
while (iLoc != l1.end())
{
if (*iLoc == aID)
{
cout << "Value " << aID << " removed from node # " << index << endl;
l1.erase(iLoc);
break;
}
index++;
iLoc++;
}
if (iLoc == l1.end())
cout << "Value not found!\n";
}
}