Initialization list
1, initialization narrowly
defined variables directly when such behavior is called narrow initialization initialization:
int a = 3;
2. General initialized
first assigned to a variable called generalized initialization condition is called initialization
int a;
...//跟a无关的代码
a = 3
Corresponds to a narrow list initialization initialization, the internal structure corresponds to the generalized function initializes
So we can solve some of variable initialization list can only be initialized with a narrow initialization, for example:
- const variables
- Quote
- No no object class configuration parameters
3, explicit: to prevent non-standard single-argument constructor call
Single-argument constructor may be called directly by =, for example:
Suppose CT class constructors a single parameter or parameters of type int int related types, then, "CT a = 3;" This wording is to be allowed of.
But such an approach is very awkward, it looks like directly assigned to the 3 a, in order to avoid such an approach, you can add in the constructor explicit, so that such wording becomes invalid.