考虑以下:
struct A {
A(int, int) { }
};
struct B {
B(A ) { } // (1)
explicit B(int, int ) { } // (2)
};
int main() {
B paren({1, 2}); // (3)
B brace{1, 2}; // (4)
}
Run Code Online (Sandbox Code Playgroud)
建设brace中(4)清楚明确地调用(2).在铛,施工paren中(3)明确要求(1),其中作为GCC 5.2,它失败编译:
main.cpp: In function 'int main()':
main.cpp:11:19: error: call of overloaded 'B(<brace-enclosed initializer list>)' is ambiguous
B paren({1, 2});
^
main.cpp:6:5: note: candidate: B::B(A)
B(A ) …Run Code Online (Sandbox Code Playgroud)