Topic: It's a question of friends...
Author: hyrosen@mail.com (Hyman Rosen)
Date: Wed, 11 Sep 2002 02:56:39 +0000 (UTC) Raw View
Kenny Stuart wrote:
> template<typename _T> class A{ friend _T; };
> template<typename _T> class A2{ typedef typename _T::P T; friend T; };
Neither of these are legal. A friend class declaration must include
the class-key, according to 11.4/2. But then 3.4.4 and 7.1.5.3 forbid
the class-name from being a typedef name or template parameter. The
upshot is that there is no way in Standard C++ to grant friendship to
a class except by naming it explicitly in the friend declaration.
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: kstuart.subs@btinternet.com ("Kenny Stuart")
Date: Tue, 10 Sep 2002 20:28:12 +0000 (UTC) Raw View
Hi all,
Can someone answer a question regarding the C++ standard and tell me if the
following non-elaborated friend declaration is legal, I can't find a section
in the standard that explicitly allows or disallows this
([14.5.3/temp.friend], [11.4/class.friend]), it works on most compilers but
g++ (GCC) 3.2 disallows it with the message 'template parameters cannot be
friends', the second example however works fine with g++.
template<typename _T>
class A{
friend _T;
};
class B{};
typedef A<B> C;
------------------------------------------------------
template<typename _T>
class A2{
typedef typename _T::its_still_me_but_not_as_a_template_parameter T;
friend T;
};
class B2{ typedef B2 its_still_me_but_not_as_a_template_parameter; };
typedef A<B2> C2;
thanks.
Kenny Stuart.
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]