Mixing Templated Argument Types
<p>How are mixed data types handled in C++ template/generic programming and overloaded operators?</p>

<p>For example, imagine that we are creating a two-dimensional coordinate class with x and y arguments, and we want to add them:</p>

<pre><code>template &lt;class T&gt;
class Cartesian {
public:
    Cartesian();
    Cartesian(T _x, T _y);
    Cartesian&lt;T&gt; operator + (const Cartesian&lt;T&gt; &amp; rhs);
    // setters, getters
private:
    T x, y;
};
</code></pre>

<p><code>+</code> operator overload to add two coordinates:</p>

<pre><code>template &lt;class T&gt;
Cartesian&lt;T&gt; Cartesian&lt;T&gt;::operator + (const Cartesian&lt;T&gt; &amp; rhs) {return Cartesian(x+rhs.x,y+rhs.y);}
</code></pre>

<p>Now, we instantiate four points: two with <code>int</code> coefficients; the other two with <code>float</code>:</p>

<pre><code>int main() {
    Cartesian&lt;int&gt; i1(1,2), i2(3,4);
    Cartesian&lt;float&gt; f1(5.7, 2.3), f2(9.8, 7.43);
</code></pre>

<p>Adding two ints is no problem, as is adding two floats. But what if we want to add an int to a float?? Even in a 4th grade classroom this would not present an issue, but here...</p>

<pre><code>(i1 + i2); // ok
(f1 + f2); // ok
(i1 + f2); // uh oh!!!
</code></pre>

<p>Is there an easy way to handle this situation? Thx! :)</p>