http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45942

--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-09 
18:07:42 UTC ---
(In reply to comment #13)
> The reason that I did not succeed in making ClassB a friend of ClassA is that
> C++ is not very logical.

Maybe so, but that's not a bug in GCC.

The next version of C++ is more lenient in what is allowed in a friend
declaration and I think it is possible to declare a typedef as a friend so you
could create a class template with a nested member and declare that member as a
friend.  That template could be specialized to make certain specializations of
classB a friend:

template<class T, int C, class AA>
struct Befriender {
  typedef int type;
};

template<class T, int C>
struct Befriender<T, C, A<T,C>> {
  typedef B<T,C,A<T,C>&> type;
};

template<class T, int C>
class A {
  friend typename Befriender<T,C,A>::type;
};

I *think* this would work, when Befriender::type results in "friend int" it is
ignored, without error.

Reply via email to