Reputation: 7369
#include <iostream>
struct Data{
Data(int){
}
}
int main(){
Data d = {0}; //#1
}
As the above code show,Does the #1 invocation contain a user-defined conversion?In my understanding about the standard ,I think it does not
For copy-list-initialization rules [dcl.init.list]
Otherwise, if T is a class type, constructors are considered. The applicable constructors are enumerated and the best one is chosen through overload resolution ([over.match], [over.match.list]). If a narrowing conversion (see below) is required to convert any of the arguments, the program is ill-formed
If no viable initializer-list constructor is found, overload resolution is performed again, where the candidate functions are all the constructors of the class T and the argument list consists of the elements of the initializer list
The standard only said the best match constructor is used to initialize the object which is initialized by using the element of initializer list
,it is different with copy-initialization(the copy-initialization say that "user-defined conversion sequences that can convert from the source type to the destination type",explicit define the copy-initialization need a user-defined conversion)
So Data d = {0}; => Data d(0);
there's no user-defined conversion other than standard conversions?Is my understanding right?
However another terms [class.conv]
Type conversions of class objects can be specified by constructors and by conversion functions. These conversions are called user-defined conversions and are used for implicit type conversions (Clause [conv]), for initialization, and for explicit type conversions
the above term means if the initialized destination type is class type and need to use constructors or conversion functions,then the conversions are "user-defined conversions"
I'm confused by these terms,what actually the Data d = {0};
is a user-defined conversion or not?
Upvotes: 0
Views: 85
Reputation: 13040
Type conversions of class objects can be specified by constructors and by conversion functions.
User-defined conversion is first a type conversion. In the initialization Data d = {0};
, there is even no type conversion, thus no user-defined conversion.
Upvotes: 0