c++ - When are temporaries created as part of a function call destroyed? -


Is a function call temporarily created as part of an argument, as long as the function ends Even if the temporary is not passed directly in the ceremony?

There is actually no chance that there was a coherent, here's an example:

  class A {public: a: x (x) {x} Printf ("Constructed A (% d) \ n", x);} ~ A () {printf ("destroyed A \ n");} int x; Int * y () {return and x;}}; Void foo (int * bar) {printf ("foo ():% d \ n", * bar); } Int main (Int arc, four ** argv) {foo (a (4) .y ()); }  

If A (4) was sent directly to foo then surely foo The call has ended, but instead I am temporarily calling a method and losing any of its references. I simply think that the temporary A will first be destroyed before foo , but the test with GCC 4.3.4 shows that it is not; The output is:

Created A (4)
foo (): 4
Destroy A

The question is, GCC What is the concept of behavior ? Or a compiler is a compiler that allows to delete a to call a foo before calling a compiler, using its member, I am inventing the pointer Am I

Temporary objects are present till the end of the entire expression in which they are created

In your example, A will be present by the A (4) object at least until the expression ends up to call After returning from foo () .

Language of this behavior is a standard guarantee:

Temporary objects are destroyed, the last step in evaluating full-expression (1.9) is that (chances) To) include the point where they were created. This is true, even though this evaluation ends in throwing an exception (C + 03 03 § 12.2 / 3).

can be extended by complying the context of a temporary life which is extended to the end of the lifespan of the context of its lifetime) or as the originator of the Constructor's initial list By using (in that case unless it is being manufactured, not fully manufactured)


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -