Home >Backend Development >C++ >What does :: mean in c++
Scope resolution operator:: is used to specify the scope of the identifier and access members in the scope, including: accessing global variables and functions, accessing class members, and accessing static members. Avoid excessive use of::, to keep the code readable and maintainable.
The meaning of :: in C
In C, :: is called Scope resolution operator. It is used to specify the scope of an identifier and access members in that scope.
Function:
<code class="cpp">int global_variable = 0; void function() { ::global_variable++; // 访问全局变量 }</code>
<code class="cpp">class MyClass { public: int member_variable; }; int main() { MyClass::member_variable = 10; // 访问类成员变量 }</code>
<code class="cpp">class MyClass { public: static int static_variable; }; int MyClass::static_variable = 10; // 声明静态成员变量 int main() { ::MyClass::static_variable++; // 访问静态成员变量 }</code>
Notes:
<code class="cpp">int x = 10; void function() { ::x++; // 访问全局变量 x }</code>
The above is the detailed content of What does :: mean in c++. For more information, please follow other related articles on the PHP Chinese website!