si******@yahoo.com wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
Hi,
I'm learning C++, and came accross the following code.
Could someone explain me why there is a line starting with :: ?
Thanks,
Andre
ModuleA::_TAO_Services_Remote_Proxy_Broker *
ModuleA::_TAO_Services_Remote_Proxy_Broker::the_TA O_Services_Remote_Pro
xy_Broker (void)
{
static ::ModuleA::_TAO_Services_Remote_Proxy_Broker
remote_proxy_broker;
return &remote_proxy_broker;
}
:: would be referring to the global namespace (as opposed to std::, for
example).
So.. If you had:
namespace MySpace
{
int open(char * name, int flags);
}
using MySpace::open;
When you try to call
open("filename", O_RDONLY);
it may be ambiguous which you mean. However, if you use:
::open("filename", O_RDONLY);
You are explicitly stating that you want the open() that's in the global
namespace (probably supplied by your compiler), instead of the open()
that's in your MySpace namespace.
Alternately, if you are in a member function of a class which has another
member named open() (as declared above), the same problem comes in. If
you use the undecorated call to open, it will call the member function,
but if you use the :: decoration, the compiler knows to use the global
namespaced function.