next up previous
Next: How do I specify Up: What are templates? Previous: How do I put

How do I write a template method of a template class?

The syntax is a bit heavy. There is no point of using it unless you realy need to.
template <class T, int N>
class   Vector
{
  T	array[N];
  template <class F>
  void	apply(F f);
};

template <class T, int N>
template <class F>
void	Vector<T, N>::apply(F function)
{
  for (int i(0); i < N; ++i) array[i] = f(array[i]);
}



Alexis Angelidis (PhD) 2005-01-11