What's the scope of the “using” declaration in C++?

后端 未结 7 634
醉话见心
醉话见心 2020-12-07 19:45

I\'m using the \'using\' declaration in C++ to add std::string and std::vector to the local namespace (to save typing unnecessary \'std::\'s).

using std::str         


        
7条回答
  •  北海茫月
    2020-12-07 20:25

    There's nothing special about header files that would keep the using declaration out. It's a simple text substitution before the compilation even starts.

    You can limit a using declaration to a scope:

    void myFunction()
    {
       using namespace std; // only applies to the function's scope
       vector myVector;
    }
    

提交回复
热议问题