Posts

Showing posts with the label function-call

Ambiguity between function and function in namespace with same argument

10 1 Can anybody explain why there is an ambiguity between A::f(const B& b) and f(const A::B& b) . I consider the code to be quite explicit about the intention. #include <iostream> namespace A { class B { protected: double value_; public: B() : value_(15.0) {} double getValue() const {return value_;} }; void f(const B& b) { std::cout << "f(b) = " << b.getValue() << std::endl; } } void f(const A::B& b) { std::cout << "Other f(b) = " << b.getValue() << std::endl; } int main() { A::B b; A::f(b); f(b); return 0; } However, both g++ 7.5.0 and clang 6.0.0 complain about ambiguous function call ( error: call of overloaded ‘f(A::B&)’ is ambiguous ) ...