using
-declarations
You can write using SFML::Render
after which you can simply call the function with Render()
, without needing the SFML::
in the front. The using
-declaration can also be scoped to a function or class. This is not possible with prefixed names.
using
-directives
You can also bring a whole namespace to the current scope with using namespace
. Everyone knows what using namespace std
does. These can also be scoped.
Namespace aliases
If you have a symbol with a long qualified name e.g. mylib::sublib::foo::bar::x
, you can write namespace baz = mylib::sublib::foo::bar
and then refer to x
with just baz::x
. These are scope-specific as well.
Among the C-style prefixed names there's usually nothing that big that would need an alias, and if there were you could just use a macro.
Adding to & removing from a namespace
If you have a file full of functions that need to be placed under a namespace x
you can simply add two lines to make it happen: namespace x {
and }
. Removing from a namespace is equally simple. With prefixed names you have to manually rename each function.
Argument-dependent lookup
You may be able to omit the namespace qualification on a function call if the function lives in the same namespace as some of its arguments. For example, if namespace baz
contains both an enum E
and a function F
that takes it, you can write F(baz::E)
instead of baz::F(baz::E)
. This can be handy if you follow the style that prefers namespaced free functions over methods.
So in conclusion, namespaces are more flexible and offer more possibilities than the prefixed naming style.