I have the following problem/question: Suppose that i have a template class Couple which have two attributes x and y of type xobject. I can easily define the sum between Couple of the same class simply defining the sum element by element, if it is defined the sum of the template object, i.e.:
Couple operator+(Couple in)
{
return Couple((*this).x+in.x,(*this).y+in.y);
}
With this implementation i can compute the sum between Couple<int>
element.
I don't exactly understand how i can define the sum between Couple<int>
and Couple<something>
inside that class.
The problem is that i cannot specialize the sum inside the class between classes that are not yet implemented, i.e., i cannot write
Couple<'int'> Couple<'int'>::operator+(Couple<'something'>)
inside the Couple class.
Do you have any idea how to do this?
My first idea was to use a second template parameter inside the operator but the results was not so good since doing this i allow only the one verse sum and not in both verse.
I hope that i explained the problem in a decent way.