Grabbing the return value before it's erased.
Hello.
I made a class:
Code:
class Test
{
public:
int a;
}; //there is no special usage for this class. I just want to show my problem
Test a_function()
{
Test temp;
temp.a = 4;
return temp;
}
int main()
{
Test b = a_function();
cout << b.a << endl;
}
//the problem is, that the return value of a_function gets destroyed BEFORE the assignment is done, thus the "cout ... " will print unexpected results.
How can I make a copy of the return value before it's destroyed.