开发者

namespace same name as function

I have this in a header:

double commonFunction( ... )
{ /*...*/ }
namespace F2
{
    double impactFactor( ... )
    { /*...*/ }
    double func( ... )
    { /*...*/ }
    double F2( ... )
    { /*...*/ }
}
namespace FL
{
    double impactFactor( ... )
    { /*...*/ }
    double func( ... )
    { /*...*/ }
    double FL( ... )
    { /*...*/ }
}

And I would like to access the F2 and FL functions from the global namespace. I tried adding this to the end of the header (or after an include, doesn't matter):

using F2::F2;
using FL::FL;

I'm sure this works when the function names differ from the namespace names, but why does this not work and how can I fix it? Thanks

PS: I can't put the functions outside their namespace, because that would lead to a redefined symbol (F2 and FL, as both namespace and function).

UPDATE: for those cursing me, here's what I did. Since this is a scientific formula header, and a good sh开发者_如何转开发ort namespace name is hard to find I named the namespaces F2 and FL and the functions themselves f2 and fL.


Because, using brings every declaration with given name into scope, so if you already have two or more declaration with one name (in this case namespace f1), it will complain.

And it has nothing to do with the name of the namespace and function being the same. Even this will generate the same error:

namespace foo
{
    void not_foo(){};
}
namespace not_foo
{
    void foo(){}
}
using not_foo::foo;


Your question is "how to access the F2 and FL functions from the global namespace.".

This is a bit ambiguous, because it could be interpreted as "how to access the F2 and FL functions which are defined in the global namespace". But from the code, I think you meant "how to access the ::F2::F2 and ::FL::FL functions from code in the global namespace"

I'm wondering what error you encounter. Also, what are the actual arguments? Without that, I can only guess. I would suggest to change the using declaration to using ::FL::FL. Still, the name lookup of FL in the global namespace will find the namespace FL, you can't hide that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜