Topic: friend class declaration


Author: "Andrei Iltchenko" <iltchenko@yahoo.com>
Date: Sat, 19 May 2001 18:46:47 GMT
Raw View
Joe Allen <joeallen@us.NOSPAMibm.com> wrote in message
news:3B052F64.FB099CE8@us.NOSPAMibm.com...
> Greetings!
>
> I've used the following C++ construct for several years on five
> different platforms, with various compilers, and I've now run across one
> where it doesn't work.
>
> class xxx {
> friend class yyy;
> friend void func_name(yyy&,......
>  ....
> }
>
> The compiler can't deal with "yyy" in the friend function declaration.
> The problem is removed when I precede my xxx class definition with
> "class yyy;".  It appears that the "friend class yyy;" statement may
> identify yyy as a "friend class", but doesn't identify it as a "class".
>
> Is this consistent with the standard, or would it be classed as a "bug"?

It is perfectly consistent with the standard. The friend class declaration
> friend class yyy;
is just an indication to the compiler that the class-name 'yyy' is a member
of the nearest enclosing namespace. But the friend declaration does not
introduce the name 'yyy' into that scope, i.e. the name will not be found by
name lookup until the class-name 'yyy' is declared in the enclosing
namespace scope either before the definition of the class xxx or after it.

There is one exception to this general rule - when a friend declaration
declares a non-member function, the name of the function can be found
through argument dependent lookup even if it's not declared in the enclosing
namespace scope. Obviously, this makes sense only if the friend function
declaration is a definition.


Regards,

Andrei Iltchenko.



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Joe Allen <joeallen@us.NOSPAMibm.com>
Date: Fri, 18 May 2001 16:49:45 GMT
Raw View
Greetings!

I've used the following C++ construct for several years on five
different platforms, with various compilers, and I've now run across one
where it doesn't work.

class xxx {
friend class yyy;
friend void func_name(yyy&,......
 ....
}

The compiler can't deal with "yyy" in the friend function declaration.
The problem is removed when I precede my xxx class definition with
"class yyy;".  It appears that the "friend class yyy;" statement may
identify yyy as a "friend class", but doesn't identify it as a "class".

Is this consistent with the standard, or would it be classed as a "bug"?

--
Joe Allen

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]