Scope resolution operator and const

前端 未结 4 1214
抹茶落季
抹茶落季 2021-01-24 03:27

Let\'s take the following code:

#include  // std::string    
using namespace std;
int main() {
  //const::int i = 42;       -> Error: \"expected         


        
4条回答
  •  醉酒成梦
    2021-01-24 04:19

    const::string is parsed as const ::string. ::string means to look up string in the global namespace, and since you have injected std into the global namespace, std::string is found and everything is dandy.

    int is a built-in type and isn't in any namespace, so there's no such thing as ::int or std::int, hence the error.

提交回复
热议问题