member function with no class name specified

Discussion in 'C++' started by John Goche, Nov 16, 2006.

  1. John Goche

    John Goche Guest

    Hello,

    I have come across the following directive but I don't see a class
    name specified in front of the ::Check function. Does anyone
    know what this means and how the directive is supposed to work?

    #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)

    Thanks,

    JG
    John Goche, Nov 16, 2006
    #1
    1. Advertising

  2. John Goche

    mlimber Guest

    John Goche wrote:
    > Hello,
    >
    > I have come across the following directive but I don't see a class
    > name specified in front of the ::Check function. Does anyone
    > know what this means and how the directive is supposed to work?
    >
    > #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)


    ::Check is a function in the global namespace.

    Cheers! --M
    mlimber, Nov 16, 2006
    #2
    1. Advertising

  3. John Goche

    VJ Guest

    mlimber wrote:
    > John Goche wrote:
    >
    >>Hello,
    >>
    >>I have come across the following directive but I don't see a class
    >>name specified in front of the ::Check function. Does anyone
    >>know what this means and how the directive is supposed to work?
    >>
    >>#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)

    >
    >
    > ::Check is a function in the global namespace.
    >


    Can it be used for functions in the nameless namespace? Or is it more
    for global functions?

    For example:

    #include <iostream>
    using namespace std;

    namespace
    {
    void f()
    {
    cout<<"222222222222"<<endl;
    }
    }

    int main()
    {
    ::f();
    }

    This will print 2's
    VJ, Nov 16, 2006
    #3
  4. URe: member function with no class name specified

    VJ wrote:
    > mlimber wrote:
    >> John Goche wrote:
    >>
    >>> Hello,
    >>>
    >>> I have come across the following directive but I don't see a class
    >>> name specified in front of the ::Check function. Does anyone
    >>> know what this means and how the directive is supposed to work?
    >>>
    >>> #define TEST2(aValue, aExpected) ::Check(aValue, aExpected,
    >>> __LINE__)

    >>
    >>
    >>>> Check is a function in the global namespace.

    >>

    >
    > Can it be used for functions in the nameless namespace? Or is it more
    > for global functions?


    Yes, it can. Unnamed/nameless/anonymous namespace names are inserted
    into the scope in which that namespace appears. The way anonymous
    namespace

    // some scope
    namespace {
    // some names declared
    }

    behaves is similar to

    // some scope
    namespace SomeWeIrD_and_UNIQUEnaME {}
    using namespace SomeWeIrD_and_UNIQUEnaME;
    namespace SomeWeIrD_and_UNIQUEnaME {
    // some names declared
    }

    (see 7.3.1.1/1); only the weird and unique name is different for
    every translation unit and is *not* available to the programmer.

    >
    > For example:
    >
    > #include <iostream>
    > using namespace std;
    >
    > namespace
    > {
    > void f()
    > {
    > cout<<"222222222222"<<endl;
    > }
    > }
    >
    > int main()
    > {
    > ::f();
    > }
    >
    > This will print 2's


    .... As it should.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Nov 16, 2006
    #4
    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. E11
    Replies:
    1
    Views:
    4,736
    Thomas Weidenfeller
    Oct 12, 2005
  2. Replies:
    12
    Views:
    720
    fluden
    Feb 11, 2005
  3. Replies:
    2
    Views:
    273
    Victor Bazarov
    Nov 16, 2006
  4. Praetorian
    Replies:
    11
    Views:
    2,346
    James Kanze
    Apr 3, 2008
  5. Peng Yu
    Replies:
    2
    Views:
    369
Loading...

Share This Page