David Blasdell said:
I have noticed (especially in multi-thread examples) :: being but before
function names, however I'm unsure what difference this makes.
Examples:
::Sleep(0);
hThread = ::CreateThread(NULL, 0, ThreadFunc, (LPVOID)kk, NULL, &dwID);
What difference does it make, if any?
Thanks
In addition to what John said, there is another place where that is often
used. That is when you are writing code inside a class, and one of the
function names in the class tree is the same as a function in the global
namespace. If you don't use the ::func() form, then you'll end up calling
the member function instead of the global function.
I see this a lot in my work. Folks writing the SDKs I use apparently like
to use the same names for functions they provide in their base classes as
the functions in the global namespace (things like MoveTo(x,y), for
example). I suppose they think it's easier to remember that way. But if
you want to call the global MoveTo instead of your object's MoveTo, then you
have to remember to prepend with ::. It's an endless headache to me!
I've known some programmers who always prepend with :: unless they're
explicitly stating the namespace, or calling a member function. That way,
if you see MoveTo(x,y), you *know* it's the member function, and can go to
the class declaration for details. But for that to work, you have to
*always* follow that rule, or else it just gets confusing!
-Howard