Creating a C++ namespace in header and source (cpp)

Namespace is just a way to mangle function signature so that they will not conflict. Some prefer the first way and other prefer the second version. Both versions do not have any effect on compile time performance. Note that namespaces are just a compile time entity.

The only problem that arises with using namespace is when we have same nested namespace names (i.e) X::X::Foo. Doing that creates more confusion with or without using keyword.


There's no performance penalties, since the resulting could would be the same, but putting your Foo into namespace implicitly introduces ambiguity in case you have Foos in different namespaces. You can get your code fubar, indeed. I'd recommend avoiding using using for this purpose.

And you have a stray { after using namespace ;-)


The difference in "namespace X" to "using namespace X" is in the first one any new declarations will be under the name space while in the second one it won't.

In your example there are no new declaration - so no difference hence no preferred way.

Tags:

C++

Namespaces