The difference between :: and . in C
Answer:
The :: and . in C are two different operators. Use For accessing class members and global members.
Detailed explanation:
1. :: (scope parsing operator)
2. . (member access operator)
Difference:
Example:
Access global variables:
<code class="cpp">int global_var = 10; cout << ::global_var; //输出 10</code>
Access class data members:
<code class="cpp">class MyClass { public: int data_member = 20; }; MyClass object; cout << object.data_member; //输出 20</code>
Resolving naming conflicts:
<code class="cpp">class MyClass { public: static int global_var = 30; }; int global_var = 40; cout << ::MyClass::global_var; //输出 30</code>
The above is the detailed content of The difference between :: and . in c++. For more information, please follow other related articles on the PHP Chinese website!