This question already has an answer here:
I've seen this a few times now, and I've been scratching my head wondering why...
As an example: (http://www.codeguru.com/forum/showthread.php?t=377394)
void LeftClick ( )
{
INPUT Input={0};
// left down
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
::SendInput(1,&Input,sizeof(INPUT));
// left up
::ZeroMemory(&Input,sizeof(INPUT));
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
::SendInput(1,&Input,sizeof(INPUT));
}
This example works without the :: (scope) operators so why are they even there?
It forces an absolute name resolution.
Without it name resolution is searched for relative to the class(s)/functions namespace path.
So assume LeftClick() is in the namespace hierarchy:
It becomes more interesting if you have a nested name:
Using the scope operator in this fashion means that you are referring to the global scope.
To save me valuable time and keystrokes, check out scope resolution operator without a scope.
The
::
is used to give access to an object directly from outside of the object.This basically mean "get the GLOBAL scoped function, instead of the currently visible one".
It's to force the symbol to be looked up at global scope.
Lets say you have the following:
If you want to call the global function
bar
from the member functionFoo::bar
you use the syntax with empty left hand side: