I had an idea for this question when I was discussing another question ( Member not zeroed, clang ++ bug? ). This question is related to C ++ 11 initialization initialization, but when I saw the C ++ 03 value initialization rule that was published there, I was confused.
The rule for initializing values ββfrom C ++ 03:
To initialize an object of type type T means:
- if T is a class type (section 9) with a constructor declared by the user (12.1), then the default constructor for T is called (and initialization is poorly formed if T does not have an accessible default constructor);
- if T is a type of non-unit class without a constructor declared by the user, then each non-static data element and component of the base class T Value is initialized;
- if T is an array type, then each element is initialized with a value;
- otherwise the object is initialized to zero
Look at the second bullet, which defines the process of initializing a value for a type without a constructor declared by the user. This rule does not mention a constructor call. As can be seen from the description of other cases of value initialization or from the default initialization description, if a constructor should be called, it will be explicitly specified in the text of the standard. I know that there is a certain form of initialization that the constructor does not call (for example, {} -initialization for aggregates), but should this be the case for initializing the value non-union class type without a user-declared constructor? An implicitly declared constructor of this type can easily be nontrivial. For instance:
class A {
public:
virtual void f() {}
};
++ 03, A, vptr ? ( , , vptr, , , .)
(- , , . . , - , , , , , , ?)
++ 03, ++ 11 . , . , , -, ( ).
EDIT: , vptr . , , ? , - .