【发布时间】:2012-08-17 14:12:23
【问题描述】:
我正在尝试重载 c++ operator== 但我遇到了一些错误...
错误 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;
}
有人可以帮忙吗?
【问题讨论】:
标签: c++ operator-overloading syntax-error friend-function