我试图重载c ++运算符==但我得到一些错误...
错误C2662:'CombatEvent :: getType':无法将'this'指针从'const CombatEvent'转换为'CombatEvent&'
这个错误就在这一行
if (lhs.getType() == rhs.getType())
Run Code Online (Sandbox Code Playgroud)
看下面的代码:
class CombatEvent {
public:
CombatEvent(void);
~CombatEvent(void);
enum CombatEventType {
AttackingType,
...
LowResourcesType
};
CombatEventType getType();
BaseAgent* getAgent();
friend bool operator<(const CombatEvent& lhs, const CombatEvent& rhs) {
if (lhs.getType() == rhs.getType())
return true;
return false;
}
friend bool operator==(const CombatEvent& lhs, const CombatEvent& rhs) {
if (lhs.getType() == rhs.getType())
return true;
return false;
}
private:
UnitType unitType;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙吗?