Can I undo the effect of “using namespace” in C++?

后端 未结 5 603
忘掉有多难
忘掉有多难 2021-01-03 18:16

With using namespace I make the whole contents of that namespace directly visible without using the namespace qualifier. This can cause problems if using

5条回答
  •  粉色の甜心
    2021-01-03 19:04

    No, C++ Standard doesn't say anything about "undo". The best you are allowed to do is to limit scope of using:

    #include 
    
    namespace Ximpl {
    
    using namespace std;    
    vector x;
    
    }
    
    vector z; // error. should be std::vector
    

    But unfortunately using namespace Ximpl will bring all names from std namespace as well.

提交回复
热议问题