|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Specifies that an instance of the type can be default constructed.
Contents |
The typeT satisfiesDefaultConstructible if all following statements and expressions are valid and have their specified effects:
| Expression/Statement | Postcondition |
|---|---|
| T u; | The objectu isdefault-initialized. |
| T u{}; | The objectu isvalue-initialized oraggregate-initialized. |
| T() T{} | A temporary object of typeT isvalue-initialized oraggregate-initialized. |
For objects of non-aggregate class type, a publicdefault constructor must be defined (either user-defined or implicitly defined) to satisfyDefaultConstructible.
Non-const objects ofnon-class object type are alwaysDefaultConstructible.
Const non-class types are notDefaultConstructible.
Const aggregate types are notDefaultConstructible if any of their members is an object of non-class type.
Non-object types (function types, reference types, and the (possibly cv-qualified) typevoid) as well as the const non-object types are neverDefaultConstructible.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 724 | C++98 | the requirements ofDefaultConstructible were missing | added |
| LWG 2170 | C++98 | initialzing an object of aDefaultConstructible type with an empty initializer could only result in value-initialization | can also lead to aggregate-initialization |
| checks if a type has a default constructor (class template)[edit] | |
(C++20) | specifies that an object of a type can be default constructed (concept)[edit] |