I believe I have the syntax correct but I'm having difficulty calling my overloaded == operator in main (last snip-it of code). Below are several files explaining the code.
Commission.h here is where the friend bool operator == exists and I believe I have it initialized correctly.
void print(Commission& emp);
int main ()
{
{
//set print options
cout << fixed << showpoint << setprecision(2);
//variable declaration
int idNum = 0; //hold input for id num
double base = 0.0; //hold input for base
double sales = 0.0; //hold input for sales
double rate = 0.0; //holds input for rate
//Initialize Commission object fred with base salary of $500
// sales of $2000 and commission rate of 10%
Commission fred(111, 500.00, 2000.00, 0.10);
print(fred);
//Create Commission object joe as default
Commission joe;
print(joe);
//
//get all attribute values for joe object
//set id num for joe
cout << endl;
while (true)
{
idNum = readInt("Enter id num: ");
if (joe.setidNum(idNum)) break;
cout << "\tInvalid IdNum"" - must be between 0 and 999, inclusively" << endl;
}
print(joe);
//set base for joe
cout << endl;
while (true)
{
base = readDbl("Enter base: ");
if (joe.setbase(base)) break;
cout << "\tInvalid base"" - must be > 0" << endl;
}
print(joe);
//set sales for joe
cout << endl;
while (true)
{
sales = readDbl("Enter sales: ");
if (joe.setSales(sales)) break;
cout << "\tInvalid sales"" - must be >= 0" << endl;
}
print(joe);
//set rate for joe
cout << endl;
while (true)
{
rate = readDbl("Enter rate: ");
if (joe.setRate(rate)) break;
cout << "\tInvalid rate"" - must be > 0.0 and <= 0.20" << endl;
}
booloperator ==(Commission& fred, Commission joe);
print(joe);
cout << endl;
} //destruct joe and fred here
//keep output window open
cout << endl;
return 0;
} //end main
//-------------------------------
//Name: print
//Purpose: print information for an employee on commission
//Parameters:
// emp - employee on commission
//Returns: nothing
//-------------------------------
void print(Commission& emp)
{
cout << "--------" << endl;
cout << "Id Num: " << emp.getidNum() << endl;
cout << "Base: " << emp.getBase();
cout << " Sales: " << emp.getSales();
cout << " Rate: " << emp.getRates();
cout << " Salary: " << emp.calcSalary() << endl;
cout << "--------" << endl;
}
//---------------------------------------------------
main.cpp line 71: booloperator ==(Commission& fred, Commission joe);
What are you doing here? It's an forward declaration, not operator call. You just never call your overloaded operator. that is the problem.
And why you are passinf fred be reference and joe by value?