::的作用非常简单,就是当局部变量和全局变量名字重叠的时候,指定某变量一定是来自全局变量。
#include<iostream>
using namespace std;
int result = 100;
int main(){
int result = 10;
if(true){
int result = 1;
cout << ::result;
}
system("pause");
return 0;
}
其输出结果是100
::的作用非常简单,就是当局部变量和全局变量名字重叠的时候,指定某变量一定是来自全局变量。
#include<iostream>
using namespace std;
int result = 100;
int main(){
int result = 10;
if(true){
int result = 1;
cout << ::result;
}
system("pause");
return 0;
}