使用后调用全局变量,例子如下:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
int atk = 200;
void test() {
int atk = 100;
cout << "局部攻击力:" << atk << endl;
//双冒号::为作用域运算符,引用全局作用域
cout << "全局攻击力:" << ::atk << endl;
}
int main() {
cout << "Hello World!" << endl;
system("pause");
test();
return EXIT_SUCCESS;
}