This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: friend-template internal error 9
- To: Romano Giannetti <romano at sirio dot iet dot unipi dot it>
- Subject: Re: friend-template internal error 9
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 07 Aug 1998 10:28:01 -0300
- Cc: egcs-bugs at cygnus dot com
- References: <19980807131137.A2607@sirio.iet.unipi.it>
Romano Giannetti <romano@sirio.iet.unipi.it> writes:
> I was trying to understang what there is behind
> -fguiding-decls and how _not_ to use it
This is covered in the FAQ, check http://egcs.cygnus.com/faq.html#friend
Unfortunately, the answer is only textual, without any example. For
your program to compile, you must pre-declare the template whose
specializations you're going to declare as friends. However, since
the template functions take specializations of a template class as
arguments, they template class must be declared before. So you get:
template <typename T> class VectorT; // so you can declare the functions:
template <typename T> T*nr(VectorT<T>&);
template <typename T> T*nrc(const VectorT<T>&);
// And now you can define the template class:
> template <class T> class VectorT { T *v; public:
// and declare the specializations of the template functions as friends:
> friend T* nr<T>(VectorT<T>& mv);
> friend T* nrc<T>(const VectorT<T>& mv);
> };
Note that you might have omitted the `T', but not the angle brackets,
in the template argument list, i.e., the following friend declarations
would be equivalent:
friend T* nr<>(Vector<T>&);
friend T* nrc<>(const VectorT<T>&);
unless there were other template functions named nr and nrc that might
have matched the argument lists; in which case the friend declarations
without the explicit template argument list would be ambiguous.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil