T is a union and all of its variant members are const.T is a non-union class with a variant member M with a non-trivial default constructor, and no variant member of the anonymous union containing M has a default member initializer.T is a union with at least one variant member with non-trivial default constructor, and no variant member of T has a default member initializer.T has a direct or virtual base or a non-static data member which has a deleted destructor, or a destructor that is inaccessible from this constructor.T has a direct or virtual base which has a deleted default constructor, or it is ambiguous or inaccessible from this constructor.T has a member (without a default member initializer) (since C++11) which has a deleted default constructor, or its default constructor is ambiguous or inaccessible from this constructor.T has a non- const-default-constructible const member without a default member initializer (since C++11).T has a member of reference type without a default initializer (since C++11).The implicitly-declared or defaulted (since C++11) default constructor for class T is undefined (until C++11) defined as deleted (since C++11) if any of the following is true: Deleted implicitly-declared default constructor If some user-defined constructors are present, the user may still force the automatic generation of a default constructor by the compiler that would be implicitly-declared otherwise with the keyword default. If this satisfies the requirements of a constexpr constructor (until C++23) constexpr function (since C++23), the generated constructor is constexpr. Class types with an empty user-provided constructor may get treated differently than those with an implicitly-defined or defaulted default constructor during value initialization. That is, it calls the default constructors of the bases and of the non-static members of this class. If the implicitly-declared default constructor is not defined as deleted, it is defined (that is, a function body is generated and compiled) by the compiler if odr-used or needed for constant evaluation (since C++11), and it has the same effect as a user-defined constructor with empty body and empty initializer list. The implicitly-declared (or defaulted on its first declaration) default constructor has an exception specification as described in dynamic exception specification (until C++17) noexcept specification (since C++17). If some user-declared constructors are present, the user may still force the automatic generation of a default constructor by the compiler that would be implicitly-declared otherwise with the keyword default. If no user-declared constructors of any kind are provided for a class type ( struct, class, or union), the compiler will always declare a default constructor as an inline public member of its class. Such constructor is treated as user-provided (see below and value initialization).ĭefault constructors are called during default initializations and value initializations. The declarator syntax of constructor only allowedĪt most one function specifier (e.g.5) Defaulted default constructor outside of class definition (the class must contain a declaration (1)). The following behavior-changing defect reports were applied retroactively to previously published C++ standards. The body of a function definition of any constructor, before the opening brace of the compound statement, may include the member initializer list, whose syntax is the colon character :, followed by the comma-separated list of one or more member-initializers, each of which has the following syntax:Ĭlass-or-identifier ( expression-list (optional) ) Note that cv- and ref-qualifiers are not allowed either: const and volatile semantics of an object under construction don't kick in until the most-derived constructor completes. The only specifiers allowed in the decl-specifier-seq of a constructor declaration are friend, inline, constexpr (since C++11), consteval (since C++20), and explicit (in particular, no return type is allowed). Where class-name must name the current class (or current instantiation of a class template), or, when declared at namespace scope or in a friend declaration, it must be a qualified class name. Constructors are declared using member function declarators of the following form:Ĭlass-name ( parameter-list (optional) ) except-spec (optional) attr (optional)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |