【发布时间】:2011-05-06 02:40:18
【问题描述】:
给定:
namespace One {
void foo(int x) {
munch(x + 1);
}
};
namespace Two {
// ... see later
}
...
void somewhere() {
using namespace Two;
foo(42);
...
以下两种变体有什么区别:
一)
namespace Two {
void foo(int x) {
munch(x + 1);
}
};
和 b)
namespace Two {
using One::foo;
};
编辑:很明显,(a) 重复了不应该是一个好主意的代码。问题更多是关于重载解析等。如果在可能的其他命名空间中还有其他 foos 或 munches 怎么办?
【问题讨论】:
-
"使用 One::foo;"被称为使用声明;使用指令是“使用命名空间 N;”。
标签: c++ namespaces using-declaration