Hello.
I made a class:
//the problem is, that the return value of a_function gets destroyed BEFORE the assignment is done, thus the "cout ... " will print unexpected results.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; }
How can I make a copy of the return value before it's destroyed.



LinkBack URL
About LinkBacks



ush_front doesn't influence the problem imho, so I left it out from the shortened version.