tags:

views:

85

answers:

3

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 short namespace name is hard to find I named the namespaces F2 and FL and the functions themselves f2 and fL.

A: 

Don't touch it this way :)

Alexander Artemenko
A: 

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.

MSalters
`error C2882: 'F2' : illegal use of namespace identifier in expression`
Gunslinger47
Hi @MSalter, can you review my answer, I have low rep and I need someone experienced to look at it, please spare few secs. Thank you.
Gollum
Nice and concise answer, with a clear example.
MSalters
+3  A: 

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;
Gollum
This is more correct.
rubenvb