即時得到這個錯誤錯誤C2440: '=':不能從 '常量BWAPI :: UNITTYPE *' 轉換爲 'BWAPI ::類型*'
錯誤C2440: '=':不能從「常量BWAPI轉換:: UNITTYPE *」到 'BWAPI ::類型*'
在該行
this->generalType = &type;
是什麼問題?由於UnitType的擴展類型不應該被允許?
class CombatEvent {
public:
CombatEvent& setType(CombatEventType type);
Type* getGeneralType() const;
private:
UnitType unitType;
Type* generalType;
}
// implementation
CombatEvent& CombatEvent::setUnitType(const UnitType type) {
this->generalType = &type;
this->unitType = type;
return *this;
}
它在CONST。 8 - )另外,你似乎在存儲一個指向臨時變量的指針,你確定要這樣做嗎? –