C++ Logo

std-proposals

Advanced search

[std-proposals] Is a default ctor struct C{C(); }; also a converting constructor

From: Sean Mayard <seanmayard_at_[hidden]>
Date: Tue, 9 Jan 2024 22:44:43 +0530
Converting ctor in C++03 had to have at least one parameter. While C++11
changed this and stated that a ctor with more than one parameter can also
be a converting ctor. In particular, according to C++11 as well as C++17:

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.
>

Note that the above quoted reference does not say if a ctor with no
parameter is a converting ctor. Then in C++17, the phrase *if any *was
added:

A constructor declared without the function-specifier explicit specifies a
> conversion from the types of its parameters *(if any)* to the type of its
> class. Such a constructor is called a converting constructor.
>

Note the highlighted *if any *that was added in C++17. This seems to
suggest that a default ctor such as *C::C(){}* is also a converting ctor.

*Was this change intentional and needed for some particular code to work? *I
mean a ctor C::C(){} doesn't convert any parameter to the class type C so
it doesn't make much sense to call it a converting constructor. So is a
default constructor supposed to be a converting constructor.

Received on 2024-01-09 17:14:55