0
我正在尝试编写一个程序,在该程序中,我可以比较两名员工总工资与重载大于运算符。为了获得总薪酬,我有一个会员职能来返回毛薪。出于某种原因,每当我去比较两个总支付我得到:作为非成员函数重载'>'
错误1错误C2662:“
double employeeclass::Employee::grosspay(void)
”:不能转换“this
”从“const employeeclass::Employee
”指针“employeeclass::Employee &
”
和
2智能感知:所述对象具有键入不与成员函数的对象类型兼容限定符是:
const employeeclass::Employee
我已经包含了给我的问题的代码段。
在.cpp:
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
#include "Employee.h"
namespace employeeclass {
bool operator> (const Employee &e1, const Employee &e2) {
if (e1.grosspay() > e2.grosspay())
return true;
else
return false;
}
}
.h文件
namespace employeeclass {
class Employee {
friend bool operator> (const Employee &e1, const Employee &e2);
}
}
听起来像'grosspay()'函数没有标记'const' –
顺便说一句if(X)return true;否则返回false;'可以更好地表示为'return X;' –
请编辑您的问题以包含[最小,完整和可验证示例](http://stackoverflow.com/help/mcve),最重要的是我们需要查看“Employee :: grosspay”的声明。 –