C/C++ 當全域變數與區域變數名稱相同時,如何使用全域變數

直接試試看下面的程式碼就知道了。
#include <iostream>
#include <string>
using namespace std;

string data = "This ia a global variable.";
int main()
{
 string data = "This is a local variable.";
 cout << ::data << endl; //在變數名稱前面加上 :: 就是指全域變數
 cout << data << endl;
 system("pause");
 return 0;
}

留言

這個網誌中的熱門文章

UVA 11321 Java