Quote:
A operator+(A &p)
{
cout<<"+ called\n";
A temp;
temp.x=x+p.x;
return temp;
}
The default constructor is called in order to create the
temp
object, you may see it replacing the above code with
A operator+(A &p)
{
A temp;
cout<<"+ called\n";
temp.x=x+p.x;
return temp;
}
Then the compiler performs a copy elision optimization (see for instance
Copy elision - cppreference.com[
^] ).