This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: friend-template internal error 9

Romano Giannetti <> 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

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
Universidade Estadual de Campinas, SP, Brasil

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]