Hi, I have a VectorN class, and a Vector3 class inherited from VectorN (which can handle cross products for example). I have trouble determining the return types of the different operators. Example:
class VectorN
{
public:
VectorN(){};
virtual VectorN operator*(const double& d) {.....};
std::vector<double> coords;
};
class Vector3 : public VectorN
{
public:
Vector3(){};
virtual Vector3 operator*(const double& d) {....};
};
This particular example produces a C2555 error : 'Vector3::operator *': overriding virtual function return type differs and is not covariant from 'VectorN::operator *', see declaration of 'VectorN::operator *'.
The problem is that I don't return a reference to a Vector3, and that the Vector3 class is not fully defined at the declaration of the operator*. However, I want my operator* to be virtual, and I want to return a Vector3 when I multiply a Vector3 with a constant (otherwise, if I do (Vector3*double).crossProduct(Vector3), it would return an error).
What can I do ?
Thanks!!