是否有逻辑上的原因,即在using namespace
的关键字之后,我们不能在using namespace
拥有一个名为myfunction
的函数, myfunction
在命名空间之外没有另一个名为myfunction
函数(具有相同的原型),但是我们可以将其用于变量( myvariable
in命名空间和myvariable
之外的myvariable
)?
Of course you can have a function with the same name and signature in different namespaces -- that's part of the reason namespaces exist. The only consideration is that if you want to call it you will have to qualify its name.
namespace Foo {
void func();
}
namespace Bar {
void func();
}
using namespace Foo;
using namespace Bar;
func(); // does not compile -- which func()?
Foo::func(); // ok
Bar::func(); // ok
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.