范围解析运算符:::
您可以指示编译器使用全局标识符代替该本地标识符传递给该标识符与 ::,范围解析运算符前缀。
:: identifier
class-name :: identifier
namespace :: identifier
备注
该 标识符 可能是变量或函数。
如果嵌套局部范围,范围解析运算符不提供对下最外面的范围的标识符。 它提供对只有全局标识符。
示例
此示例具有名为 amount的两个变量。 第一个是全局的并包含值 123。 第二个是本地。主函数。 范围解析运算符指示编译器使用全局 amount 而不是本地的一个。
// expre_ScopeResolutionOperator.cpp
// compile with: /EHsc
// Demonstrate scope resolution operator
#include <iostream>
using namespace std;
int amount = 123; // A global variable
int main() {
int amount = 456; // A local variable
cout << ::amount << endl // Print the global variable
<< amount << endl; // Print the local variable
}