Different return value of an overridden class
- by Samer Afach
I have a simple but confusing question here. Is it legal to have a different return value type for overridden methods than the abstact ones defined in the base class?? I did that and the compiler didn't complain... could someone please explain?
class MyBaseClass
{
int value;
public:
virtual int getValue() = 0;
};
class MyClass : public MyBaseClass
{
double value;
public:
virtual double getValue(); // here!!! return is double, not int
};
double MyClass::getValue()
{
return this->value;
}
The compiler totally accepted something similar (MSVC und MinGW)... could anyone please exaplain to what extent this is legal?