line starting with ::

Discussion in 'C++' started by sieg1974@yahoo.com, May 10, 2005.

  1. Guest

    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;
    }
    , May 10, 2005
    #1
    1. Advertising

  2. Andre Kostur Guest

    wrote in
    news::

    > 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.
    Andre Kostur, May 10, 2005
    #2
    1. Advertising

  3. Phlip Guest

    sieg1974 wrote:

    > 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

    --
    Phlip
    http://www.c2.com/cgi/wiki?ZeekLand
    Phlip, May 10, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john bailo
    Replies:
    0
    Views:
    631
    john bailo
    Aug 13, 2003
  2. Hugo
    Replies:
    10
    Views:
    1,292
    Matt Humphrey
    Oct 18, 2004
  3. kaushikshome
    Replies:
    4
    Views:
    755
    kaushikshome
    Sep 10, 2006
  4. scad
    Replies:
    23
    Views:
    1,146
    Alf P. Steinbach
    May 17, 2009
  5. Marek Stepanek
    Replies:
    12
    Views:
    402
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page