[class.conv.ctor]

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

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

### 11.4.8 Conversions [[class.conv]](class.conv#ctor)

#### 11.4.8.2 Conversion by constructor [class.conv.ctor]

[1](#1)

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

A constructor that is not explicit ([[dcl.fct.spec]](dcl.fct.spec "9.2.3 Function specifiers"))
specifies a conversion from
the types of its parameters (if any)
to the type of its class[.](#1.sentence-1)

[*Example [1](#example-1)*:

[ð](#:Jessie)

struct X { X(int);
 X(const char*, int = 0);
 X(int, int);};

void f(X arg) { X a = 1; // a = X(1) X b = "Jessie"; // b = X("Jessie",0) a = 2; // a = X(2) f(3); // f(X(3)) f({1, 2}); // f(X(1,2))} â *end example*]

[2](#2)

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

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

An explicit constructor constructs objects just like non-explicit
constructors, but does so only where the direct-initialization syntax ([[dcl.init]](dcl.init "9.5 Initializers"))
or where casts ([[expr.static.cast]](expr.static.cast "7.6.1.9 Static cast"), [[expr.cast]](expr.cast "7.6.3 Explicit type conversion (cast notation)")) are explicitly
used; see also [[over.match.copy]](over.match.copy "12.2.2.5 Copy-initialization of class by user-defined conversion")[.](#2.sentence-1)

A default constructor can be an explicit constructor; such a constructor
will be used to perform default-initialization
or value-initialization ([[dcl.init]](dcl.init "9.5 Initializers"))[.](#2.sentence-2)

[*Example [2](#example-2)*: struct Z {explicit Z(); explicit Z(int); explicit Z(int, int);};

Z a; // OK, default-initialization performed Z b{}; // OK, direct initialization syntax used Z c = {}; // error: copy-list-initialization Z a1 = 1; // error: no implicit conversion Z a3 = Z(1); // OK, direct initialization syntax used Z a2(1); // OK, direct initialization syntax used Z* p = new Z(1); // OK, direct initialization syntax used Z a4 = (Z)1; // OK, explicit cast used Z a5 = static_cast<Z>(1); // OK, explicit cast used Z a6 = { 3, 4 }; // error: no implicit conversion â *end example*]

â *end note*]
