次の点を考慮してください。
struct X {
template <class T> operator T(); // #1
template <class T> operator T&(); // #2
};
int a = X{}; // error: ambiguous
int& b = X{}; // calls #2
int const& c = X{}; // calls #2
の状況b
は簡単で、#2
実行可能な唯一の候補です。の初期化に#2
は が好まれるが、 の初期化には 2 つがあいまいであることを示すルールは何ですか?#1
int const&
int