-
In some cases, you may find that you want to use a using directive because the namespace name is just too long. In such cases, you should consider a namespace alias instead, e.g.,
Code:
namespace jimblumberg
{
void foo()
{
// ...
}
}
// ...
namespace jbb = jimblumberg;
jbb::foo();
-
Or you may have some nested namespaces that are too long. Then you can also use an alias to shorten it up.
Code:
namespace jimblumberg
{
void foo();
{
}
namespace laserlight
{
void bar()
{
}
}
}
namespace jimblumberg::laserlight = jbll;
jbll::bar();
Jim
-
I always make my namespaces up to 6 characters long (the global one is usually the same as the target binary, e.g. for target 'prog32.exe' I use namespace 'prog' etc.) so there is no need to prefix names with long scope names.
And maybe someone has already mentioned about it:
If you place a 'using' declaration with a namespace you will be able to access all of the namespaces that are used within the specified namespace.
If 'first' is using 'std' and 'second' is using 'first', then 'second' is using 'std' too.
-
I prefer to fully qualify my namespaces.
Code:
std::cout << "Hello World" << std::endl;
I have had problems with the using directive in the past, the same function defined in the global namespace and in namespace std. It took me several hours to find the problem, and thanks to forum members I finally was able to fix the problem.
Jim