[class.ctor.general]

# 11 Classes [[class]](./#class)

## 11.4 Class members [[class.mem]](class.mem#class.ctor.general)

### 11.4.5 Constructors [[class.ctor]](class.ctor#general)

#### 11.4.5.1 General [class.ctor.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1240)

A [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") declares a [*constructor*](#def:constructor "11.4.5.1 General [class.ctor.general]") if it is a
function declarator ([[dcl.fct]](dcl.fct "9.3.4.6 Functions")) of the form

[*ptr-declarator*](dcl.decl.general#nt:ptr-declarator "9.3.1 General [dcl.decl.general]") ( [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]") ) [*noexcept-specifier*](except.spec#nt:noexcept-specifier "14.5 Exception specifications [except.spec]")opt [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt

where the [*ptr-declarator*](dcl.decl.general#nt:ptr-declarator "9.3.1 General [dcl.decl.general]") consists solely of an[*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]"), an optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]"),
and optional surrounding parentheses, and the [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") has
one of the following forms:

- [(1.1)](#1.1)

in a friend declaration ([[class.friend]](class.friend "11.8.4 Friends")),
the [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") is a [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") that names a constructor ([[class.qual]](class.qual "6.5.5.2 Class members"));

- [(1.2)](#1.2)

otherwise, in a [*member-declaration*](class.mem.general#nt:member-declaration "11.4.1 General [class.mem.general]") that belongs to the[*member-specification*](class.mem.general#nt:member-specification "11.4.1 General [class.mem.general]") of a class or class template,
the [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") is the
injected-class-name ([[class.pre]](class.pre "11.1 Preamble")) of the immediately-enclosing entity;

- [(1.3)](#1.3)

otherwise, the[*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") is a [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") whose [*unqualified-id*](expr.prim.id.unqual#nt:unqualified-id "7.5.5.2 Unqualified names [expr.prim.id.unqual]") is
the injected-class-name of its lookup context[.](#1.sentence-1)

Constructors do not have names[.](#1.sentence-2)

In a constructor declaration, each [*decl-specifier*](dcl.spec.general#nt:decl-specifier "9.2.1 General [dcl.spec.general]") in the optional[*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]") shall befriend,inline,constexpr,consteval, or
an [*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]")[.](#1.sentence-3)

[*Example [1](#example-1)*: struct S { S(); // declares the constructor};

S::S() { } // defines the constructor â *end example*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1285)

A constructor is used to initialize objects of its class type[.](#2.sentence-1)

[*Note [1](#note-1)*:

Because constructors do not have names, they are never found during
unqualified name lookup; however an explicit type conversion using the functional
notation ([[expr.type.conv]](expr.type.conv "7.6.1.4 Explicit type conversion (functional notation)")) will cause a constructor to be called to
initialize an object[.](#2.sentence-2)

The syntax looks like an explicit call of the constructor[.](#2.sentence-3)

â *end note*]

[*Example [2](#example-2)*: complex zz = complex(1,2.3);
cprint( complex(7.8,1.2) ); â *end example*]

[*Note [2](#note-2)*:

For initialization of objects of class type see [[class.init]](class.init "11.9 Initialization")[.](#2.sentence-4)

â *end note*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1305)

An object created in this way is unnamed[.](#3.sentence-1)

[*Note [3](#note-3)*:

[[class.temporary]](class.temporary "6.8.7 Temporary objects") describes the lifetime of temporary objects[.](#3.sentence-2)

â *end note*]

[*Note [4](#note-4)*:

Explicit constructor calls do not yield lvalues, see [[basic.lval]](basic.lval "7.2.1 Value category")[.](#3.sentence-3)

â *end note*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1315)

[*Note [5](#note-5)*:

Some language constructs have special semantics when used during construction;
see [[class.base.init]](class.base.init "11.9.3 Initializing bases and members") and [[class.cdtor]](class.cdtor "11.9.5 Construction and destruction")[.](#4.sentence-1)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1322)

A constructor can be invoked for aconst,volatile orconstvolatile object[.](#5.sentence-1)

const andvolatile semantics ([[dcl.type.cv]](dcl.type.cv "9.2.9.2 The cv-qualifiers")) are not applied on an object under construction[.](#5.sentence-2)

They come into effect when the constructor for the
most derived object ([[intro.object]](intro.object "6.8.2 Object model")) ends[.](#5.sentence-3)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1340)

The address of a constructor shall not be taken[.](#6.sentence-1)

[*Note [6](#note-6)*:

A return statement in the body of a constructor
cannot specify a return value ([[stmt.return]](stmt.return "8.8.4 The return statement"))[.](#6.sentence-2)

â *end note*]

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1349)

A constructor shall not be a coroutine[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L1352)

A constructor shall not have an explicit object parameter ([[dcl.fct]](dcl.fct "9.3.4.6 Functions"))[.](#8.sentence-1)
