您好,登錄后才能下訂單哦!
把做工程過程中經常用的內容段珍藏起來,下邊資料是關于C++演示在不同的范圍內不沖突使用同名變量的范例的內容。
#include <iostream>
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。