Prototypes:
class A;
A func(A obj2)
{
return obj2;
};
int main()
{
A obj1;
A obj3 = func(obj1);
return 0;
}
While passing arguments to a function by value, it is copied from calling function's stack variable(obj1) to called function's stack variable(obj2), without any temporary object. Then why can't it be same way while returning by value from the function. i.e obj2 can be copied to obj3 directly without creating any temporary object(Forget RVO here).
Is it because func() can be called without collecting its return value? or there some other logic behind the scene?