Topic: Templates and friends?


Author: lang@ind.e-technik.uni-stuttgart.de (Martin Lang)
Date: 24 May 1994 06:36:29 GMT
Raw View

This morning I went into a problem concerning templates and friend functions.
Consider the following class template declaration

template<class T, unsigned int dim>
class Array
{
   T rep[dim];
...

   friend ostream& operator<<(ostream&, Array<T,dim>&);
};


The output operator is a friend to class Array and must itself be a
template function, e.g.:

template<class T, unsigned int dim>
ostream& operator<<(ostream&, Array<T,dim>& rhs)
{
...
}


The problem now is, that the ARM says that template arguments of a function
template must be types, i.e. the 'dim' argument is invalid and Cfront
complains about that. For the Array declaration, the 'dim' argument is
legal, and if any function has an argument of type Array<T,dim> it must
be a template function.

I think, the ARM is not clear in this point. Can someone please comment this?


Thanks,

Martin Lang
University of Stuttgart







Author: jason@cygnus.com (Jason Merrill)
Date: Tue, 24 May 1994 08:03:09 GMT
Raw View
>>>>> Martin Lang <lang@ind.e-technik.uni-stuttgart.de> writes:

> I think, the ARM is not clear in this point. Can someone please comment
> this?

I think the ARM is very clear about that.  However, this restriction has
been dropped from the WP, and will not be part of the eventual standard.

Jason