Scope Resolution Operator Usage Without Scope
In C , the scope resolution operator (::) allows access to global members or members of a namespace even when there is no scope present. When used without a scope, as in the example ::foo(), it signifies global scope.
Purpose
The scope resolution operator used without a scope has the following purposes:
Example
Consider the following example:
void bar(); // global function class foo { void some_func() { ::bar(); } // calls global bar(), not class version void bar(); // class member };
In this example, if we want to call the global bar() function from within the class member function some_func(), we need to use ::bar() to explicitly specify the global scope. Otherwise, it would attempt to call the class member bar().
The above is the detailed content of When and Why Use the Scope Resolution Operator (::) Without a Scope in C ?. For more information, please follow other related articles on the PHP Chinese website!