D
David Williams
Hi all,
I have a templated Vector3D class which holds (x,y,z) components as the
specified type. I quite often wish to cast a Vector3D holding ints into
a Vector3D holding floats and vice versa. Like so:
Vector3D<int> intVec(10,20,30);
Vector3D<float> floatVec = intVec;
Of course this doesn't work. I would be happy if instead the following
worked:
Vector3D<int> intVec(10,20,30);
Vector3D<float> floatVec = static_cast< Vector3D<float> >(intVec);
but of course that doesn't either. I have read online that it is not
possible to overload the static_cast operator (why, incidently?) but
what is the best approach to this problem? Ideally I would like the
first example to compile but generate a warning and the second example
to be fine (as works for built-in types).
Any thoughts appriciated,
David
I have a templated Vector3D class which holds (x,y,z) components as the
specified type. I quite often wish to cast a Vector3D holding ints into
a Vector3D holding floats and vice versa. Like so:
Vector3D<int> intVec(10,20,30);
Vector3D<float> floatVec = intVec;
Of course this doesn't work. I would be happy if instead the following
worked:
Vector3D<int> intVec(10,20,30);
Vector3D<float> floatVec = static_cast< Vector3D<float> >(intVec);
but of course that doesn't either. I have read online that it is not
possible to overload the static_cast operator (why, incidently?) but
what is the best approach to this problem? Ideally I would like the
first example to compile but generate a warning and the second example
to be fine (as works for built-in types).
Any thoughts appriciated,
David