Home > Back-end >  String (const String & STR) and String & operator=(const String & STR) which is the assignment const
String (const String & STR) and String & operator=(const String & STR) which is the assignment const

Time:10-01

String (const String& STR) and String& Operator=(const String& Which is the assignment constructor STR)?

Feeling

String STR (" hello "); And the String STR="hello"; Is the assignment operation

CodePudding user response:

You see books written inside, the former is the copy constructor, the latter is through operator overloading "=" realize the assignment of functions,

CodePudding user response:

Distinguish between structure and assignment,
In a narrow sense said:
Structure is initialized, detail and have a lot of concepts, what values as initialization, initialization, directly copy initialization, aggregate initialization, initialization list... Reference:
https://en.cppreference.com/w/cpp/language/initialization; Say from another aspect and display initialization, implicitly initialized,

Assignment was conducted after initialization change integral value, is called copy assignment, the whole copy, only the operator=,

Difference between structure and the key of the assignment is that structure is a statement in the time of initial value,

So only copy, copy assignment, no copy assignment,

` ` `
String STR (" hello ");//there is type declaration in front, followed by parentheses can also see that must have been constructed, this is called structure directly, also showed that the structure,

String STR="hello".//in front of a type declaration, it must be constructed, with the=sign, is an implicit structure, implicit call with direct constructor String (const char *)

` ` `

CodePudding user response:

refer to the second floor SDGHCHJ response:
distinguish tectonic and assignment,
thank you! Good complex

CodePudding user response:

Just to learn, share knowledge:
https://www.cnblogs.com/ymy124/p/3638132.html

CodePudding user response:

The teacher this sentence to summarize is to separate the
"=" represents the initialization and assignment is the key to question whether the object already exists (has been constructed), if not, it is initialized, it should call a constructor or copy constructor (as the case may be); If present, is the assignment, you should call assignment operator function,

CodePudding user response:

reference 5 floor thousand dream life reply:
the teacher this sentence to summarize is to separate the
"=" represents the initialization and assignment is the key to question whether the object already exists (has been constructed), if not, it is initialized, it should call a constructor or copy constructor (as the case may be); If present, is the assignment, you should call assignment operator function,
wow!!!!!!!!!!!!!!!!!!! sobering
  • Related