4

I came across the following code structure in C++:

uint32_t AClass::Action(....)
{
..
      status = ::Action(...);
..
}

I am not sure what ::Action() means. Which class does it belongs to? NOTE: the argument list of ::Action(...) is different from AClass::Action(...).

The Vivandiere
  • 3,059
  • 3
  • 28
  • 50
drdot
  • 3,215
  • 9
  • 46
  • 81

2 Answers2

13

The leading :: just means that Action here refers to a non-member function in the global namespace, instead of referring to AClass::Action in the current namespace.

Sam Estep
  • 12,974
  • 2
  • 37
  • 75
  • how do i find out where the root namespace is? – drdot Jul 07 '15 at 19:34
  • 1
    @dannycrane I suppose the root namespace could also be called the "default" namespace. Any code that isn't in an explicit `namespace` block is in the root namespace. All other namespaces are essentially "inside" the root namespace. – Sam Estep Jul 07 '15 at 19:36
  • 1
    @RedRoboHood Would be nice if you can distinguish the root namespace from Global scope – The Vivandiere Jul 07 '15 at 19:39
  • @StraightLine They're more or less interchangeable. You can find more information [here](http://stackoverflow.com/questions/10269012/global-scope-vs-global-namespace) if you're especially interested. – Sam Estep Jul 07 '15 at 19:41
  • 1
    There is such a thing as "the global namespace". There is no such thing as "the root namespace". – Barry Jul 07 '15 at 19:46
  • @Barry OK, thanks. I'll edit my answer. – Sam Estep Jul 07 '15 at 19:47
-2

::Action() mean it is a function under the the global namespace.

Anis Belaid
  • 304
  • 2
  • 8