Direct initialization and replication Initialization
Source: Internet
Author: User
1. classtest CT1 ("AB"); this statement is directly initialized. It does not need to call the copy constructor and directly calls the const char * PC ), so when the replication constructor becomes private, it can still be executed directly. 2. classtest CT2 = "AB"; this statement is replication initialization. It first calls the const classtest (const char * PC) function to create a temporary object and then calls the copy constructor, use this temporary object as a parameter to construct the CT2 object. Therefore, when the replication constructor becomes private, the statement cannot be compiled. 3. classtest ct3 = CT1; this statement is for replication initialization. Because CT1 already exists, you do not need to call the relevant constructor, but directly call the replication constructor, copy the value to the object ct3. When the copy constructor becomes private, the statement cannot be compiled. 4. classtest ct4 (CT1); this statement is directly initialized. Because CT1 already exists, the copy constructor is called directly to generate the copy object ct4 of the object ct3. Therefore, when the copy constructor becomes private, the statement cannot be compiled.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service