Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How does Argument-Dependent-Lookup work for namespace-scope friend fucntion?

Reply
Thread Tools

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

 
 
neverhoodboy
Guest
Posts: n/a
 
      03-04-2012
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.
}
 
Reply With Quote
 
 
 
 
Johannes Schaub
Guest
Posts: n/a
 
      03-04-2012
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.
 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM



Advertisments