W3 Sunday __c++ There are too many subtle to egg-ache details. Like a constructor that can make so many moths.

Source: Internet
Author: User
Tags shallow copy

? questions raised

is mainly in the VC + + 2015 often hints of inexplicable compilation errors.

To analyze why the constructor in Java is a simple question:

1. The object types in C + + are not only passed by reference, but may also be copied for delivery. So sometimes you have to provide a copy constructor . (This is the same as the overloaded assignment operator = seemingly purpose?) To be able to construct a 2nd instance based on 1 instance)

If you do not explicitly customize a copy constructor, the compiler provides a "shallow copy" by default. Therefore: When a member variable contains a pointer type for an object, the copy constructor must be overridden. --rewriting is almost inevitable?

2. There are 2 things in C + + that have an initial value and a list of initialization .

3. The constructor and copy constructor provided by default can also be deleted by the "= delete" function. I don't know what the situation is. ( slot: C + + Adds a lot of detail to the grammar with syntactic sugar, making the syntax quite miscellaneous, motherfucker )

4. Although there is only one C + + specification, the compiler that implements the specification has several products: MSVC, g++, Clang ... And they each have a bunch of versions, support for C + + standards, additions are different, not to mention there are still some static code check the rules are not the same, give the message I often do not understand ... Can only take Google and then face a lot of grammatical details, want to die ...

? "Default Initialization"

1. If a constructor is not explicitly provided, the compiler provides a default parameterless constructor ("default constructor").

"C + + Primer":

Or Baidu know understood Point:--> Design Section test code, debug look to know.

? The answer is here

Auto-Initialization of C + + variables

W3 Sunday __c++ There are too many subtle to egg-ache details. Like a constructor that can make so many moths.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.