Specifies that an instance of the type can be default constructed.
The type T
satisfies DefaultConstructible if.
Given.
u
, an arbitrary identifier The following expressions must be valid and have their specified effects.
Expression | Post-conditions |
---|---|
T u; | The object u is default-initialized |
T u{}; | The object u is value-initialized or aggregate-initialized. |
T()
| A temporary object of type T is value-initialized or aggregate-initialized. |
For objects of non-aggregate class type, a public default constructor must be defined (either user-defined or implicitly defined) to satisfy DefaultConstructible.
Non-const objects of non-class object type are always DefaultConstructible.
Const non-class types are not DefaultConstructible.
Const aggregate types are not DefaultConstructible if any of their members is an object of non-class type.
Non-object types (function types, reference types, and the (possibly cv-qualified) type void) as well as the const non-object types are never DefaultConstructible.
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 of DefaultConstructible were missing | added |
(C++11)(C++11)(C++11) | checks if a type has a default constructor (class template) |
(C++20) | specifies that an object of a type can be default constructed (concept) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/named_req/DefaultConstructible