Why operator overloading fails?
<p>In the following codes, I illustrate an example of operator overloading:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

template &lt;typename T&gt;
class A
{
public:
    A()   {};
    A( T &amp;obj) {value = obj;};
    ~A() {};
    T value;
    template &lt;typename E&gt;
    A&lt;T&gt;&amp; operator = (const A&lt;E&gt; &amp;obj)
    {
        cout&lt;&lt;"equal operator"&lt;&lt;endl;
        if(this == &amp;obj)
            return *this;

        value = obj.value;
        return *this;
    }

};



int main()
{
    int temp;
    temp = 3;
    A&lt;int&gt; myobjects(temp);
    cout&lt;&lt;myobjects.value&lt;&lt;endl;

    temp = 7;
    A&lt;int&gt; yourobjects(temp);
    yourobjects = myobjects;
    cout&lt;&lt;yourobjects.value&lt;&lt;endl;



    return 0;
}
</code></pre>

<p>However, when I debug this program, I find that the main program does not invoke the equal operator overloading function. However, if I change the equal operator in the following way:</p>

<pre><code>   A&lt;T&gt;&amp; operator = (const A&lt;T&gt; &amp;obj)
    {
        cout&lt;&lt;"equal operator"&lt;&lt;endl;
        if(this == &amp;obj)
            return *this;

        value = obj.value;
        return *this;
    }
</code></pre>

<p>It will work. Do you have any ideas why the initial function does not work? </p>
