Tôi cố gắng để quá tải C++ toán tử == nhưng im nhận được một số lỗi ...C++ lỗi C2662 không thể chuyển đổi 'này' con trỏ từ 'Loại const' thành 'Loại &'
lỗi C2662: 'CombatEvent: : getType': không thể chuyển đổi 'này' con trỏ từ 'CombatEvent const' thành 'CombatEvent &'
lỗi này là tại dòng này
if (lhs.getType() == rhs.getType())
xem mã dưới đây:
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;
}
ai cũng có thể trợ giúp?
Rất thông minh. Đã cho tôi một vài phút để nắm bắt đầy đủ ý tưởng. Cảm ơn nhiều. –