我试图重载C++的运算符==,但是出现了一些错误...
Error C2662:“CombatEvent::getType”:无法将“this”指针从“const CombatEvent”转换为“CombatEvent&”。
这个错误出现在这一行:
if (lhs.getType() == rhs.getType())
看下面的代码:
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;
}
有人能帮忙吗?