重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
把做工程过程中经常用的内容段珍藏起来,下边资料是关于C++演示在不同的范围内不冲突使用同名变量的范例的内容。
创新互联专业为企业提供磴口网站建设、磴口做网站、磴口网站设计、磴口网站制作等企业网站建设、网页设计与制作、磴口企业网站模板建站服务,十年磴口做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
#include
using std::cout;
using std::endl;
{
public:
};
{
}
{
return x;
}
int main()
{
abc a;
cout << "Scope within class abc: x = " << a.x
<< "nScope within namespace def: x = " << def::x
<< "nScope within function getx: x = " << getx()
<< "nScope within global scope : x = " << ::x
<< "nScope within local main function: x = " << x;
{
cout << "nScope within local code block: x = " << x;
}
return 0;
}
Scope within class abc: x = 10
Scope within namespace def: x = 20
Scope within function getx: x = 30
Scope within global scope : x = 40
Scope within local main function: x = 50
Scope within local code block: x = 60