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.conv.ctor below:

[class.conv.ctor]

12.3.1 Conversion by constructor [class.conv.ctor]

A constructor declared without the function-specifier explicit specifies a conversion from the types of its parameters to the type of its class. Such a constructor is called a converting constructor. [ Example:

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

void f(X arg) {
  X a = 1;            X b = "Jessie";     a = 2;              f(3);               f({1, 2});        }

 — end example ]

An explicit constructor constructs objects just like non-explicit constructors, but does so only where the direct-initialization syntax ([dcl.init]) or where casts ([expr.static.cast], [expr.cast]) are explicitly used. A default constructor may be an explicit constructor; such a constructor will be used to perform default-initialization or value-initialization ([dcl.init]). [ Example:

struct Z {
  explicit Z();
  explicit Z(int);
  explicit Z(int, int);
};

Z a;                            Z a1 = 1;                       Z a3 = Z(1);                    Z a2(1);                        Z* p = new Z(1);                Z a4 = (Z)1;                    Z a5 = static_cast<Z>(1);       Z a6 = { 3, 4 };                

 — end example ]

A non-explicit copy/move constructor ([class.copy]) is a converting constructor. An implicitly-declared copy/move constructor is not an explicit constructor; it may be called for implicit type conversions.


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