In C + + primer 5, in the section on string, there is this sentence:
string " Hiya "; // Copy Initialization
In other words, this is the copy initialization, which is called the copy constructor. And the following sentence:
string S6 ("hiya"// Direct Initialization
But it is also directly initialized, and then I think, in the initialization of C + + above these two are not equivalent? In addition I am also very curious in the implementation of the string string s5 = "Hiya"; If it is true that the copy is initialized, there is no intermediate generation of a temporary variable (though it is unlikely that the write efficiency is obviously very low). So go to see the SGI STL source code, find about operator = part is this:
operator= (const _chart* __s) / WC: = char* return Assign (__s, _ _s + _traits::length (__s)); }
It is clear that there is no intermediate variable to produce.
I used these two ways to step through vs:
int Main (intChar* argv[]) { int0; string " WC " ; string str2 ("wcww"); return 0
It is then found that both of these initialization statements enter the same constructor, which is the following:
Basic_string (const _elem *_ptr) : _mybase () { // construct from [_ptr, <null>) _tidy (); Assign (_ptr); }
And this is not a copy constructor, just a general constructor. So the structure of the top two sentences belongs to the direct structure without copy construction.
operator about the string of C + + =