Sorry, I couldn't find simillar topic.
dynamic_cast inside operator's code wouldn't solve this problem?
EDIT: Here's simple example compiled with -std=c++03 and it works, why sfml can't do this?
#include <iostream>
#include <memory>
template<typename T>
struct MyVector
{
T x;
T y;
MyVector()
: x(0),
y(0)
{ }
MyVector(T x, T y)
{
this->x = x;
this->y = y;
}
template<typename U>
MyVector<T> operator +(MyVector<U> vect)
{
return MyVector<T>(this->x + vect.x, this->y + vect.y);
}
template<typename U>
MyVector<T> & operator=(MyVector<U> vect)
{
x = static_cast<T>(vect.x);
y = static_cast<T>(vect.y);
}
template<typename U>
MyVector<T> & operator+=(MyVector<U> vect)
{
return (*this) = (*this) + vect;
}
};
int main()
{
MyVector<float> fVec(2.4f, 3.9f);
MyVector<int> iVec(5, 5);
iVec += fVec;
std::cout << "[" << iVec.x << " " << iVec.y << "]" << std::endl;
return 0;
}