Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel Krügler<daniel.kruegler@googlemail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: Question about argument-dependent-lookup for namespace-scope friend function |
| Date | 2012-03-06 08:50 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <jj22ae$j5m$1@dont-email.me> (permalink) |
| References | <fc3ca60e-4998-45f9-9da4-ff26cca65005@q8g2000pbe.googlegroups.com> |
On 2012-03-04 23:25, neverhoodboy wrote:
> 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); // will this compile?
> }
IMO the call of funcb is supposed to be ill-formed. According to 3.4.2
p4 b2:
"Any namespace-scope friend functions or friend function templates
declared in associated classes are visible [..]"
but for a non-template class BBB, only BBB itself (and not AAA) is an
associated class.
HTH& Greetings from Bremen,
Daniel Krügler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Find similar
Question about argument-dependent-lookup for namespace-scope friend function neverhoodboy <xinjie.wang@gmail.com> - 2012-03-04 14:25 -0800 Re: Question about argument-dependent-lookup for namespace-scope friend function Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-03-06 08:50 -0800
csiph-web