我不明白为什么会出现“重载函数调用不明确”的错误。
在“main”之前,我声明使用了命名空间“second”。
我的预期输出是:
``` 这是第一个foo 这是第二个foo 这是第二个foo ```
``` 这是第一个foo 这是第二个foo 这是第二个foo ```
#include <iostream>
using namespace std;
namespace first {
void foo() {
cout << "this is the first foo" << endl;
}
}
namespace second {
void foo() {
cout << "this is the second foo" << endl;
}
}
void foo() {
cout << "this is just foo" << endl;
}
using namespace second;
void main() {
first::foo();
second::foo();
foo();
}
foos
。现在你应该使用::foo()
或者second::foo()
。 - Steveusing namespace second
时,你扩展了工作命名空间为second
。为了澄清你想从哪个初始工作空间调用函数,你应该使用<namespace>::foo
,全局命名空间的名称为空。 - 273Kusing namespace ...
参见此文章。 - Peter VARGA