Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 23rd, 2005, 05:17 AM
sieg1974@yahoo.com
Guest
 
Posts: n/a
Default line starting with ::

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

  #2  
Old July 23rd, 2005, 05:17 AM
Andre Kostur
Guest
 
Posts: n/a
Default Re: line starting with ::

sieg1974@yahoo.com wrote in
news:1115736340.859319.142700@o13g2000cwo.googlegr oups.com:
[color=blue]
> 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;
> }
>
>[/color]

:: 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.
  #3  
Old July 23rd, 2005, 05:17 AM
Phlip
Guest
 
Posts: n/a
Default Re: line starting with ::

sieg1974 wrote:
[color=blue]
> I'm learning C++, and came accross the following code.
> Could someone explain me why there is a line starting with :: ?[/color]

Google for C++ scope resolution operator

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles