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)重复代码,这永远不应该是一个好主意。问题更多的是有关重载分辨率等......如果在其他命名空间中有其他foo
s或munch
es会怎么样?
“using One :: foo;”被称为使用声明; using-directive是“using namespace N;”。 – 2010-11-06 19:39:31