Код: Выделить всё
class A {
public:
A(int i) {}
A(bool b) {}
};
class B {
public:
operator int() { return 1; };
operator bool() { return false; };
operator A() { return A(1); }; // I added this conversion operator to remove ambiguity
};
struct S {
A a;
};
int main() {
B b;
A a{b}; // this works
S s1{.a = b}; // this also works
// error: conversion from '
' to 'A' is ambiguous
S s2{.a{b}}; // this does not work
return 0;
}
< /code>
Я добавил оператор оператора конверсии a () {return a (1); }; Код: Выделить всё
A a{b}; // this works
S s1{.a = b}; // this also works
< /code>
Но строка < /p>
S s2{.a{b}}; // this does not work
< /code>
все еще не компилируется. Почему это? В
clang version 21.0.0git (https://github.com/llvm/llvm-project.git 5c3a99760274a06f8cb7e7247ce69c2fde5fbf2a) Подробнее здесь: https://stackoverflow.com/questions/796 ... -ambiguity