Possible Duplicate:
How can I “unuse” a namespace?
After declaring "using namespace mynamespace", for example, is it possible to stop using that namespace mid-code?
Thanks for your help.
Possible Duplicate:
How can I “unuse” a namespace?
After declaring "using namespace mynamespace", for example, is it possible to stop using that namespace mid-code?
Thanks for your help.
Take a look at the C++ documentation on Namespaces.
http://www.cplusplus.com/doc/tutorial/namespaces/
You can declare that you are 'using' a namespace for a specific scope (such as a function). But I don't believe you can arbitrarily specify where a using statement starts and ends, it is always for the rest of the scope it is declared in.
I should note (someone please correct me if I'm wrong) that in C++ you can arbitrarily declare a scope almost anywhere you want, simply by using curly braces.
{
using mynamespace;
/* rest of your code here */
}
But use it sparingly and carefully, because if used too often or in the wrong context, it can make code harder to read (which defeats the whole point of 'using' in the first place, right?).
You cannot stop using namespace
in your code. But you can do some smart changes to your code to simulate that effect.
.cpp
files
and use using namespace
into only those
files where actually neededusing namespace
facility towards
the bottom of the file, so that
upper code will not be having the
using
effect.using namespace
inside another namespace / function. See
example.No, I think that namespace will be available to you for entire .cpp file, but if you want to use an object of same name from some other namespace you can always use fully qualified name!