About return const reference in C++
<p>I am confused about returning the const reference in C++. So i write below code block and test on gnu c++ and visual studio. And find different answer. Could anyone tell the benefit using return const reference in C++ and the reason cause different behavior on differnt compiler.</p>

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

class A
{
public:
A(int num1, int num2):m_num1(num1), m_num2(num2)
{
    cout&lt;&lt;"A::A"&lt;&lt;endl;
}
const A&amp; operator * (const A &amp; rhs) const
{
    return A(this-&gt;m_num1 * rhs.m_num1, this-&gt;m_num2*rhs.m_num1);
}

A(const A&amp; rhs)
{
    this-&gt;m_num1 = rhs.m_num1;
    this-&gt;m_num2 = rhs.m_num2;
    cout&lt;&lt;"A::A(A&amp;)"&lt;&lt;endl;
}
const A&amp; operator = (const A&amp; rhs)
{
    cout&lt;&lt;"A::Operator="&lt;&lt;endl;
    return *this;
}
void Display();
private:
int m_num1;
int m_num2;
};
void A::Display()
{
cout&lt;&lt;"num1:"&lt;&lt;m_num1&lt;&lt;" num2:"&lt;&lt;m_num2&lt;&lt;endl;
}
int main()
{
A a1(2,3), a2(3,4);
A a3 = a1 * a2;
a3.Display();
return 0;
}
</code></pre>

<p>On Gnu C++, it did report the correct answer. But failed on visual studion compiler.</p>
