When I try to compile my project I get a C2440 error saying 'initializing' : cannot convert from 'vector<component_count>' to 'vector_2D'. The MSDN documentation on C2440 says The compiler cannot cast from 'type1' to 'type2'. I have a base class, vector:
template <unsigned int component_count>
class vector {...}
and a derived class, vector_2D:
class vector_2D : public vector<2>
My base class defines a default and copy constructor, and operator overloads. The code which gives me the error is:
vector_2D character_position = pen_position + vector_2D(offset_x, offset_y);
pen_position is created earlier as
vector_2D pen_position(string_position);
I can’t seem to fix my error. Can anyone point out what is going wrong and/or how to fix it?
is the problem. You’re returning a base and then trying to assign it to the derived.
The simplest fix is to provide an overload