Question about :: operator

This is a discussion on Question about :: operator within the C++ Programming forums, part of the General Programming Boards category; whats the difference between:
Code:
return ::CallNextHookEx(sg_hGetMsgHook, code, wParam, lParam);
and
Code:
return CallNextHookEx(sg_hGetMsgHook, code, wParam, lParam);
Also, I've seen ...

It's the scope operator. In the first example, the difference is that the first one will always look in the global namespace. The second will look in whatever current namespace it's in plus the global namespace. So if you a function named A in the global namespace and in namespace B and you happen to be defining a function inside namespace B and you to use the global function A, you prefix it with :: to use the global one.

The second syntax depends on what object and function is. The :: operator can be used to access members of a namespace. Any static members inside a class are said to be part of the class's namespace. Thus, to access them, you would type the class's name followed by :: and the name of whatever you want to access.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Members declared by a using-declaration can be referred to by explicit qualification just like other member
names (3.4.3.2). In a using-declaration, a prefix :: refers to the global namespace.

There's also this, in the context of expressions instead of using declarations:

Originally Posted by C++ Standard, clause 5.1, paragraph 4

The operator :: followed by an identifier, a qualified-id, or an operator-function-id is a primaryexpression.
Its type is specified by the declaration of the identifier, qualified-id, or operator-function-id.
The result is the entity denoted by the identifier, qualified-id, or operator-function-id. The result is an
lvalue if the entity is a function or variable. The identifier, qualified-id, or operator-function-id shall have
global namespace scope or be visible in global scope because of a using-directive (7.3.4). [Note: the use of
:: allows a type, an object, a function, an enumerator, or a namespace declared in the global namespace to
be referred to even if its identifier has been hidden (3.4.3). ]

Hmm, no. A class defines a class scope. A namespace defines a namespace scope. A namespace declarative region differs from a class declarative region in that it can be unnamed and it can span across several translation units.

Originally Posted by ISO/IEC 14882:2003(E), §7.3.(1), page 114

A namespace is an optionally-named declarative region. The name of a namespace can be used to access entities declared in that namespace; that is, the members of the namespace. Unlike other declarative regions, the definition of a namespace can be split over several parts of one or more translation units.