hello everyone,
could anyone please explain what is the difference implementation of the below codes? I got that Lvalue is defined any entities that you can have the reference to it and in rvalue this is meaningless.
1 2 3
// assume we have class A
A a; // a
a=A(); //A() is rvalue
In addition to it A() still re-initialize a to stack?
If the default constructor and/or destructor of A has observable side effects, the observable behaviour of a=A(); would be "as-if" an anonymous temporary object of type A was constructed, the prvalue was move assigned, and the anonymous temporary object was then destroyed.
The C++ standard is only concerned about the lifetime of an object, and the duration for which the storage for an object would be available.
In this case, the object is an anonymous temporary, and
temporary objects are destroyed as the last step in evaluating the full-expression that (lexically) contains the point where they were created, and if multiple temporary objects were created, they are destroyed in the order opposite to the order of creation. http://en.cppreference.com/w/cpp/language/lifetime
Subject to the above requirement, an implementation is free to create a temporary object where ever it pleases; in practice, most implementations use a runtime stack for acquiring storage that can be reclaimed within a short period of time.