C++ Logo

std-proposals

Advanced search

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

From: connor horman <chorman64_at_[hidden]>
Date: Tue, 9 Jan 2024 12:33:52 -0500
You can copy-list-initialize from `{}` if you have a non-explicit default
constructor. You thus convert from the empty initializer list to C. Thus, I
would call this a converting constructor.

On Tue, 9 Jan 2024 at 12:14, Sean Mayard via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-01-09 17:34:06