Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:DefaultConstructible

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      Specifies that an instance of the type can be default constructed.

      Contents

      [edit]Requirements

      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.

      [edit]Notes

      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.

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 724C++98the requirements ofDefaultConstructible were missingadded
      LWG 2170C++98initialzing an object of aDefaultConstructible type with an
      empty initializer could only result in value-initialization
      can also lead to
      aggregate-initialization

      [edit]See also

      checks if a type has a default constructor
      (class template)[edit]
      specifies that an object of a type can be default constructed
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/DefaultConstructible&oldid=177195"

      [8]ページ先頭

      ©2009-2025 Movatter.jp