Apologies everyone for that ghastly amount of code.
I'm having an issue regarding my use of comparative operators. I've looked up the previous topics that some have asked here before regarding this issue, but most are incomplete topics that never got a true resolved ending. I'm hoping to have assistance from beginning to end on what is supposed to be simple, yet troublesome when I'm trying to apply it.
So far, I have these two persistent errors:
binarytree.h(125): error C2678: binary '==': no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion) |
binarytree.h(129): error C2678: binary '<': no operator found which takes a left-hand operand of type 'EmployeeInfo' (or there is no acceptable conversion) |
What's bothering me is the difference of left-hand and right-hand operands. I'm not the type to really use the actual technical terms, which I guess is my crutch when these kinds of errors pop up. What I'm trying to get from this is that there is meant to be a '==' and '<' overload in EmployeeInfo, right?
Well, here's the EmployeeInfo.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#pragma once
#include <string>
using namespace std;
class EmployeeInfo {
private:
int empID;
string empName;
public:
// Default & Overload Constructor
EmployeeInfo();
// Mutators
void setEmpID(int);
void setEmpName(string);
// Accessors
int getEmpID();
string getEmpName();
// Operator < Overload
//bool operator < (const EmployeeInfo &);
bool operator < (const EmployeeInfo &y) {
if (empID < y.empID) {
return true;
}
return false;
}
// Operator == Overload
//bool operator == (const EmployeeInfo &);
bool operator == (const EmployeeInfo &z) {
if (empID == z.empID) {
return true;
}
else {
return false;
}
}
};
| |
No matter where I place these overloads in EmployeeInfo.h or .cpp, these overload errors stick around. If I place these overloads in BinaryTree.h, a whole new set of problems occur first since it doesn't know what 'EmployeeInfo' is, of course.
So, do these overloads need to be mentioned in BinaryTree? Or are they meant to be in EmployeeInfo? If the latter, how are they meant to be there, exactly?
I can provide the other files if they are needed. The purpose is to create a program/application that can handle an employee's ID and Name in a BinaryTree. The user is only meant to search for an employee based on their ID, a search will be called, and will come back outputting a matching employee's ID and Name.