Re: Can a construction function call another construntor ?
The temporary lasts until the end of the expression it's created in, unless it's bound to a const reference, in which case, it has the lifetime of the reference.
Standard, 12.2/3:
[...]Temporary objects are destroyed as the last step in evaluating the full-expression (1.9) that (lexically) contains the point where they were created. [...]
And paragraphs 4 & 5:
4 There are two contexts in which temporaries are destroyed at a different point than the end of the full-expression. The first context is when an expression appears as an initializer for a declarator defining an object. In that context, the temporary that holds the result of the expression shall persist until the object’s initialization is complete. [...]
5 The second context is when a reference is bound to a temporary. The temporary to which the reference is bound or the temporary that is the complete object to a subobject of which the temporary is bound persists for the lifetime of the reference except as specified below. [...]
(The exceptions are mostly just clarifications and don't make much difference to the argument.)
Code:
A::A(a); // Dies almost immediately
const A& r = A::A(a); // Dies when r goes out of scope
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell