November 1999
Intermediate to advanced
336 pages
6h 29m
English
Another path that leads to temporary object creation is function return value. If you code a function that returns an object by value (as opposed to a reference or pointer), you can easily end up with a temporary. Consider f() as a simple example:
string f()
{
string s;
... // Compute "s"
return s;
}
The return value of f() is an object of type string. A temporary is generated to hold that return value. For example:
String p; ... p = f();
The temporary object holding f()'s return value is then assigned to the left-hand side object p. For a more concrete example consider the string operator+. This operator will implement the intuitive interpretation of string "+" operation. It takes two input string objects and returns a new ...
Read now
Unlock full access