蒲公英110

作用域解析运算符

::的作用非常简单,就是当局部变量和全局变量名字重叠的时候,指定某变量一定是来自全局变量。

#include<iostream>
using namespace std;
void display();
int result = 100;
int main()
{
int result = 10;
if (true){
int result = 1;
cout <<result<<endl;
cout <<::result << endl;
}
cout << result<<endl;
cout << ::result << endl;
display();
// cout << result << endl;
system("pause");
return 0;
}
void display()
{
cout << result << endl;
}

 

posted on 2016-08-22 16:15  蒲公英110  阅读(532)  评论(0编辑  收藏  举报

导航