Quick A: When it is assigned.
Recently on SO:
When is an rvalue evaluated?
s2
binds to the expressions1 + s1
, but is this evaluated at the times2
is assignedYes.
And also woulds2
hold memory for a temporary string?Precisely,
s2
is bound to a temporarystd::string
.
s1 + s1
will produce a temporarystd::string
, which will be bound to the references2
(and its lifetime is extended to the lifetime of the reference). Thens2 += "Test";
, performsoperator+=()
ons2
, i.e. the temporarystd::string
.
Add a Comment
Comments are closed.