Open utterances-bot opened 2 years ago
Hi, thanks for the article. But I'm a little bit confused by your "Postpone Variable Definitions" part. For V2, "V2 invokes both the default ctor and the assignment operator.". As far as I know, Only copy ctor will be called for V2 like V3. How it is possible that invokes assignment operator for V2. The std::string s2 newly created object by another existing.
Hey, good catch! you're correct here and I'm wrong. I believe what I meant here was the following:
std::string s2;
...
s2 = s1;
I haven't looked too deep into this but perhaps by now the compiler can even remove the initial ctor call and directly invoke copy ctor.
I'll update this at some point.
Essential C++ - Implementation | Ray
Table of Contents
http://oneraynyday.github.io/dev/2017/09/19/Essential-C++-5/