line starting with ::

S

sieg1974

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_TAO_Services_Remote_Proxy_Broker
(void)
{
static ::ModuleA::_TAO_Services_Remote_Proxy_Broker
remote_proxy_broker;
return &remote_proxy_broker;
}
 
A

Andre Kostur

(e-mail address removed) wrote in
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_TAO_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::eek:pen;


When you try to call

open("filename", O_RDONLY);

it may be ambiguous which you mean. However, if you use:

::eek:pen("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.
 
P

Phlip

sieg1974 said:
I'm learning C++, and came accross the following code.
Could someone explain me why there is a line starting with :: ?

Google for C++ scope resolution operator
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top