I've got a method that follows
class BuildOrderStrategy
{
public:
virtual const Urgency& getUrgency() = 0;
...
}
which implementation follows
const Urgency& RandomBuildOrderStrategy::getUrgency()
{
return NULL;
}
but at compile time I'm getting this error
error C2440: 'return' : cannot convert from 'int' to 'const Urgency &'
at this time I really do want to return a NULL value from getUrgency method.. so.. what is the problem with my code? how can I fix it? I came from java world where this is completely possible..
the code of Urgency is this
class Urgency : public Investment
{
private:
public:
Urgency(BWAPI::UnitType type1, BWAPI::UpgradeType type2, BWAPI::TechType type3);
~Urgency(void);
};
Returning NULL from this type of function doesn't make a lot of sense. You probably want a pointer not a reference.
NULL is defined as 0 ( or even (void*)0 ) and since 0 is an integer that is what you are returning in this function which doesn't work with a reference ( which has to reference an actual object )
In this case returning a pointer to a Urgency object in your function makes more sense. So try changing the reference to a pointer.
const Urgency* RandomBuildOrderStrategy::getUrgency()
{
return NULL;
}
Or even try returning an Urgency type that has been initialized in a special way that allowed you to check later if it is "empty".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With