How does Argument-Dependent-Lookup work for namespace-scope friend fucntion?

Discussion in 'C++' started by neverhoodboy, Mar 4, 2012.

  1. neverhoodboy

    neverhoodboy Guest

    We know that argument-dependent-lookup can be used to find namespace-
    scope friend function defined in some class which is otherwise not
    visible using an ordinary lookup. My question is, can the argument be
    of some class in the same namespace other the enclosing class of the
    friend function? Please see the following code snippet:

    namespace NNN
    {
    class BBB {};
    class AAA
    {
    public:
    friend void func() {}
    friend void funca(AAA&) {}
    friend void funcb(BBB&) {}
    };
    }

    int main()
    {
    NNN::AAA a;
    NNN::BBB b;
    NNN::func(); // this will fail to compile for sure
    funca(a); // this will compile with no problem because of ADL
    funcb(b); // shall this compile? various compilers at my hand
    give different results, so I'm asking for help to understand the exact
    requirement of the C++ standards.
    }
     
    neverhoodboy, Mar 4, 2012
    #1
    1. Advertising

  2. Re: How does Argument-Dependent-Lookup work for namespace-scope friendfucntion?

    Am 04.03.2012 12:31, schrieb neverhoodboy:
    > We know that argument-dependent-lookup can be used to find namespace-
    > scope friend function defined in some class which is otherwise not
    > visible using an ordinary lookup. My question is, can the argument be
    > of some class in the same namespace other the enclosing class of the
    > friend function? Please see the following code snippet:
    >



    No it cannot, unless the other class brings the first class in
    consideration by making it an associated class (because, for example,
    the first class is a base class of the other class).

    That you get varying results from different compilers is because the C++
    specification was unclear in the past and was updated by defect reports
    to be clear that unassociated classes do not make their friend function
    declarations visible to ADL.
     
    Johannes Schaub, Mar 4, 2012
    #2
    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. Martin Vorbrodt

    argument dependent lookup

    Martin Vorbrodt, Oct 25, 2005, in forum: C++
    Replies:
    13
    Views:
    542
    Default User
    Oct 25, 2005
  2. siddhu

    Argument-Dependent Lookup

    siddhu, May 14, 2007, in forum: C++
    Replies:
    1
    Views:
    367
    Old Wolf
    May 14, 2007
  3. siddhu

    Argument-Dependent Lookup

    siddhu, May 14, 2007, in forum: C++
    Replies:
    4
    Views:
    519
    James Kanze
    May 15, 2007
  4. Belebele
    Replies:
    6
    Views:
    452
    Belebele
    Dec 11, 2007
  5. Replies:
    2
    Views:
    463
    Balog Pal
    Apr 9, 2009
Loading...

Share This Page