Should this be ambiguous or not? (implicit casts)

后端 未结 1 1960
我在风中等你
我在风中等你 2021-02-12 10:25
 struct A 
 {
     A(const A& src);
     A(const char* src);
 };
 struct B 
 {
     operator A();
     operator char*();
 };
 void test()  
 {
     B v;
     A s(v);         


        
1条回答
  •  不思量自难忘°
    2021-02-12 10:44

    Yes, the expected result is Ambiguity to the best of my interpretation of Clause 13.3.3.2

    Matching argument 'v' of type 'B' to the parameters of either of the overloaded constructors of 'A' requires a user defined conversion. There both the sequences are of CONVERSION rank.

    My interpretation is that the following quote from $13.3.3.2 applies

    [...]User-defined conversion sequence U1 is a better conversion sequence than another user-defined conversion sequence U2 if they contain the same user-defined conversion function or constructor and if the second standard conversion sequence of U1 is better than the second standard conversion sequence of U2.

    Both of these invoke different conversion functions in class 'B'. Therefore, I think the first condition itself is not satisfied and hence the expected result is Ambiguity as nither of the conversion sequences is better than the other.

    0 讨论(0)
提交回复
热议问题