Let's consider the following piece of code:
std::string&& rvalue_reference_1 = std::string("some string");
std::string   regular_string("some string");
std::string&& rvalue_reference_2 = "some string";
- 
Are the first and the second statements behaving the same way ? I understand the first one as constructing a temporary object, and then simply "assigning a name" to it. Thus it becomes a regular object. Am I wrong somewhere ?
 - 
In the third statement, I'm not sure to understand what happens under the hood. "some string" is an anonymous/temporary
const char*, and rvalue_reference_2 a rvalue reference to astd::stringobject, not a rvalue reference to aconst char*... By writingstd::string&&, do we implicitly callstd::string's constructor? 
Aucun commentaire:
Enregistrer un commentaire