Ambiguity between function and function in namespace with same argument
10
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
) regardless of compiler flags and optimizations.
c++ namespaces function-call argument-dependent-lookup
New contributor
rc4559 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
-
2Another day, another victim of ADL – Yksisarvinen 16 hours ago
Add a comment
|