A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://timsong-cpp.github.io/cppwp/n4140/class.ctor below:

12 Special member functions [special]

12.1 Constructors [class.ctor]

Constructors do not have names. A declaration of a constructor uses a function declarator ([dcl.fct]) of the form

ptr-declarator ( parameter-declaration-clause ) exception-specificationopt attribute-specifier-seqopt

where the ptr-declarator consists solely of an id-expression, an optional attribute-specifier-seq, and optional surrounding parentheses, and the id-expression has one of the following forms:

The class-name shall not be a typedef-name. In a constructor declaration, each decl-specifier in the optional decl-specifier-seq shall be friend, inline, explicit, or constexpr. [ Example:

struct S {
  S();              };

S::S() { }          

 — end example ]

A constructor is used to initialize objects of its class type. Because constructors do not have names, they are never found during name lookup; however an explicit type conversion using the functional notation ([expr.type.conv]) will cause a constructor to be called to initialize an object. [ Note: For initialization of objects of class type see [class.init].  — end note ]

A constructor can be invoked for a const, volatile or const volatile object. const and volatile semantics ([dcl.type.cv]) are not applied on an object under construction. They come into effect when the constructor for the most derived object ([intro.object]) ends.

A default constructor for a class X is a constructor of class X that can be called without an argument. If there is no user-declared constructor for class X, a constructor having no parameters is implicitly declared as defaulted ([dcl.fct.def]). An implicitly-declared default constructor is an inline public member of its class. A defaulted default constructor for class X is defined as deleted if:

A default constructor is trivial if it is not user-provided and if:

Otherwise, the default constructor is non-trivial.

A default constructor that is defaulted and not defined as deleted is implicitly defined when it is odr-used ([basic.def.odr]) to create an object of its class type ([intro.object]) or when it is explicitly defaulted after its first declaration. The implicitly-defined default constructor performs the set of initializations of the class that would be performed by a user-written default constructor for that class with no ctor-initializer ([class.base.init]) and an empty compound-statement. If that user-written default constructor would be ill-formed, the program is ill-formed. If that user-written default constructor would satisfy the requirements of a constexpr constructor ([dcl.constexpr]), the implicitly-defined default constructor is constexpr. Before the defaulted default constructor for a class is implicitly defined, all the non-user-provided default constructors for its base classes and its non-static data members shall have been implicitly defined. [ Note: An implicitly-declared default constructor has an exception-specification ([except.spec]). An explicitly-defaulted definition might have an implicit exception-specification, see [dcl.fct.def].  — end note ]

Note: [class.base.init] describes the order in which constructors for base classes and non-static data members are called and describes how arguments can be specified for the calls to these constructors.  — end note ]

A return statement in the body of a constructor shall not specify a return value. The address of a constructor shall not be taken.

A functional notation type conversion ([expr.type.conv]) can be used to create new objects of its type. [ Note: The syntax looks like an explicit call of the constructor.  — end note ] [ Example:

complex zz = complex(1,2.3);
cprint( complex(7.8,1.2) );

 — end example ]

An object created in this way is unnamed. [ Note: [class.temporary] describes the lifetime of temporary objects.  — end note ] [ Note: Explicit constructor calls do not yield lvalues, see [basic.lval].  — end note ]

During the construction of a const object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor's this pointer, the value of the object or subobject thus obtained is unspecified. [ Example:

struct C;
void no_opt(C*);

struct C {
  int c;
  C() : c(0) { no_opt(this); }
};

const C cobj;

void no_opt(C* cptr) {
  int i = cobj.c * 100;           cptr->c = 1;
  cout << cobj.c * 100                 << '\n';
}

 — end example ]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4