根据https://en.cppreference.com/w/cpp/language/injected-class-name
在类作用域中,当前类的名称被视为公共成员名称;这称为注入类名。名称的声明点紧跟在类定义的左大括号之后。
int X;
struct X {
void f() {
X* p; // OK. X refers to the injected-class-name
::X* q; // Error: name lookup finds a variable name, which hides the struct name
}
};
那么代码中到底发生了什么?X* p
变成X::X* p
了?