What is the difference between :: std :: string and std :: string?

what is the difference between ::std::string and std::string The first is global? But global for what? Is the std namespace global? Thanks for helping me.

+7
c ++
source share
1 answer

::std::string means string in the std in the global namespace. Host :: forces the search to search in the global namespace. Therefore ::std::string always means the type of string from the C ++ standard library.

std::string means string in the std , where std will be displayed in the current area. Therefore, if there is a class, namespace, or enumeration named std , a name lookup may find that std .

 #include <string> namespace foo { namespace std { class string { ... }; namespace bar { std::string s; // means foo::std::string ::std::string s; // means string from standard library } } } 

There is no need to use a leading :: if you and your partners agree not to name anything std . It is just a good style.

+14
source share

All Articles