任何人都可以解释为什么A::f(const B& b)和之间存在歧义f(const A::B& b)。我认为代码对意图非常明确。
#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;
}
Run Code Online (Sandbox Code Playgroud)
然而,error: call of overloaded ‘f(A::B&)’ is …