I had to spend some time searching and fixing the error that I managed to single out in the following code:
#include <iostream> struct A { std::string S; A(const std::string s) { S = s; } }; void f1(A a) { std::cout << "f1:aS = " << aS << "\n"; } void f1(const std::string s) { std::cout << "f1:s = " << s << "\n"; } void f2(A a) { std::cout << "f2:aS = " << aS << "\n"; } int main() { f1(A("test")); f1(std::string("test")); f2(A("test")); f2(std::string("test")); return 0; }
The error was caused by the missed (by me and the compiler (?)) Ambiguity created by the f1 function: f2 clearly shows that both f1(A) and f1(std::string) are applied to A , but the ambiguity is not selected during compilation by the compiler, and when executed, the output is:
f1:aS = test f1:s = test f2:aS = test f2:aS = test
Is this behavior right? Compiler problem? Or just an old PIBCAK?
c ++ ambiguity
slashmais Nov 25 '12 at 19:27 2012-11-25 19:27
source share