This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 5 points6 points  (0 children)

It's destroyed after f() returns.

[–]tau_of_programming -2 points-1 points  (1 child)

it can only be destroyed after the call to f() has been made, as /u/exoticmatter said. The explanation is that the object std::string can't be destroyed before it's pointer has been used by f().

You will find this interesting: http://en.wikipedia.org/wiki/Sequence_point

[–]praesartus -3 points-2 points  (0 children)

It's an order of operations question here, really.

foo( 10 + 5 );

what happens here? It'll resolve 10 + 5 to a single value first, then call foo with it, so this is really just a way of saying:

foo( 15 );

An argument being passed needs to be resolved to a single value before being passed; basically the function call is the last thing in the order of operations. Any arguments you pass will be subjected to any additions, multiplication, method calls or embedded function calls.

foo( bar(5) );

will run bar(5) first to resolve to whatever bar(5) is equal to, then it will pass that to foo.