In all our c++ courses, all the teachers always put using namespace std;
right after the #include
s in their .h
files. This seems to me
With regards to "Is there some way to undo [a using
declaration]?"
I think it is useful to point out that using
declarations are affected by scope.
#include
{ // begin a new scope with {
using namespace std;
vector myVector; // std::vector is used
} // end the scope with }
vector myOtherVector; // error vector undefined
std::vector mySTDVector // no error std::vector is fully qualified
So effectively yes. By limiting the scope of the using
declaration its effect only lasts within that scope; it is 'undone' when that scope ends.
When the using
declaration is declared in a file outside of any other scope it has file-scope and affects everything in that file.
In the case of a header file, if the using
declaration is at file-scope this will extend to the scope of any file the header is included in.