我在标题中有这个:
double commonFunction( ... )
{ /*...*/ }
namespace F2
{
double impactFactor( ... )
{ /*...*/ }
double func( ... )
{ /*...*/ }
double F2( ... )
{ /*...*/ }
}
namespace FL
{
double impactFactor( ... )
{ /*...*/ }
double func( ... )
{ /*...*/ }
double FL( ... )
{ /*...*/ }
}
Run Code Online (Sandbox Code Playgroud)
我想从全局命名空间访问F2和FL函数.我尝试将其添加到标题的末尾(或者在包含之后,无关紧要):
using F2::F2;
using FL::FL;
Run Code Online (Sandbox Code Playgroud)
我确定当函数名称与命名空间名称不同时,这是有效的,但为什么这不起作用,我该如何解决?谢谢
PS:我不能将函数放在它们的命名空间之外,因为这会导致重新定义的符号(F2和FL,作为命名空间和函数).
更新:对于那些诅咒我的人,这就是我的所作所为.由于这是一个科学的公式标题,并且很难找到一个好的短名称空间名称,因此命名为名称空间F2和FL以及函数本身f2和fL.
因为,using将具有给定名称的每个声明带入范围,因此如果您已经有两个或更多具有一个名称的声明(在这种情况下namespace f1),它将会抱怨.
和它无关,与命名空间和功能是相同的名称.即便这样也会产生同样的错误:
namespace foo
{
void not_foo(){};
}
namespace not_foo
{
void foo(){}
}
using not_foo::foo;
Run Code Online (Sandbox Code Playgroud)