Monday, 16 May 2016

c++ - Is `using namespace foo;` useless?

Suppose I have a library that places all its declarations in namespace foo. I can then conveniently use the library by adding:



using namespace foo;


to my source files. However, if any innocent name in foo (for example class foo::socket) is now ambiguous with global namespace names (for example ::socket()). What's more, there is no way to disambiguate them! Looks like using namespace is only useful for libraries that don't conflict with the global namespace, or am I missing something?



EDIT: by "disambiguate" I meant once for the scope, not at every use site, which is of course possible.




I guess we'll have to wait for modules for a satisfactory solution.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...