2

I came across a piece of code which looks like this:

::GetSystemDirectory(buffer, MAX_PATH);

I've never seen a function call preceded by an empty ::. I've always seen them being used with namespaces.

Can someone please explain me what does an empty :: mean ?

brainydexter
  • 19,826
  • 28
  • 77
  • 115

1 Answers1

8

It's the scope resolution operator. With nothing in front of it, it indicates global scope.

So for instance, suppose you have a class that defines its own GetSystemDirectory method. Within the code of a method of that class, to call the global one, you'd need the :: in front of it, otherwise by default you'd get the one specific to the class. (And similarly for namespaces.)

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875