This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: template parameters cannot be friends
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: naje <najeiv at ukr dot net>, llewelly at xmission dot com, gcc-help at gcc dot gnu dot org
- Date: Fri, 21 May 2004 11:30:57 -0500
- Subject: Re: template parameters cannot be friends
- References: <E1BRCAi-000BW6-00@storage.ukr.net>
Hi Naje,
>but it's working with typedef's can anybody explain need of this?
It is? It shouldn't!
A typedef is a simple alias.
My GCC fails. (OS & GCC details below.)
- - - - - - - - - - - - -
class Bar;
class Quux;
template <typename T>
class Foo
{
typedef T T2;
friend T2; // fail
friend class Bar; // OK
typedef Quux T3;
friend class T3; // Hmmm.
};
- - - - - - - - - - - - -
The "friend class T3" worked on my GCC. I expected it to introduce
(forward declare) a "class T3", not use the T3 alias to Quux... but it did,
so there you go. I haven't needed or used "friend" for many years.
Another thought...
You may be able to get away with using a BOOST static assert in a two-stage
template Draw function, which compares the T class to Button<T2> class, to
make sure that T and T2 are the same.
But I think what you really have a misapplication of the static
polymorphism paradigm.
HTH,
--Eljay
------ system details -------
$ uname -a
CYGWIN_NT-5.1 mn-eljayet 1.5.9(0.112/4/2) 2004-03-18 23:05 i686 unknown
unknown Cygwin
$ gcc --version
gcc (GCC) 3.3.1 (cygming special)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.