gpt4 book ai didi

c++ - 错误 C2440 : '=' : cannot convert from 'const BWAPI::UnitType *' to 'BWAPI::Type *'

转载 作者:行者123 更新时间:2023-11-28 03:32:31 26 4
gpt4 key购买 nike

我收到这个错误

错误 C2440:“=”:无法从“const BWAPI::UnitType *”转换为“BWAPI::Type *”

在这一行

this->generalType = &type;   

问题是什么?因为 UnitType extends Type 不应该被允许吗?

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。这应该工作。但是,您正在传递值。您可以通过 const UnitType& 代替。这提高了性能。当然,如果您通过引用传递,也可以删除违规行中的 address-of 运算符。

关于c++ - 错误 C2440 : '=' : cannot convert from 'const BWAPI::UnitType *' to 'BWAPI::Type *' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12068779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com