C ++范围解析运算符
使用范围解析运算符(::)的原因有很多。例如:如果全局变量名称与本地变量名称相同,则将使用范围解析运算符来调用全局变量。它还用于在类外部定义函数,并用于访问类的静态变量。
这是C++语言中的作用域解析运算符的示例,
示例
#include <iostream>
using namespace std;
char a = 'm';
static int b = 50;
int main() {
char a = 's';
cout << "The static variable : "<< ::b;
cout << "\nThe local variable : " << a;
cout << "\nThe global variable : " << ::a;
return 0;
}输出结果
这是输出
The static variable : 50 The local variable : s The global variable : m