#Order of object creation
21 messages · Page 1 of 1 (latest)
When your question is answered use !solved or the button below to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
I'm 99% sure it will just instantiate the object a single time.
Either that or the String("hello") will create a string, then text will be move constructed using that temporary.
I am almost certain. This would be a case of return value optimization, so the String("hello") will construct directly to text
Key point is that there is NO default construction happening.
type name = value;
is fundamentally different from
type name;
name = value;
At least for class types anyway
Wait, the reason why it will be move constructed is because you used a Rvalue to construct right? And the overload for an Rvalue constructor is probably certainly moving the value in
it's guaranteed by the standard
Yea, true, I know about that elision thing
So when does it actually call the constructor instead of eluding it?
Wait, I think i misspoke, shouldn't it always be calling that constructor?
it won't call the move constructor in your original example
Basically the construction of would have been the temporary is done to text directly
Why not?
I mean, not for the String("hello") bit, but it would've been called for text tho right?
this
My understanding of that bit of code its equivalent to
String text("hello");
Instead of having two memory locations, one for the temp and one for the variable, the optimization is just to have the one memory location for text and have the construction of the temporary write DIRECTLY to text's memeory
ye, so basically like the equivalent I said?
Yes, but that isn't a move construction. It's calling the
String(const char*) constructor
oh wait true