Template function as an argument to a function

mi60607 mi60607@swt.edu
Tue May 2 12:57:00 GMT 2000


Is it not possible to pass a template function to a function
as an argument? I tried it and I got following error message:

  g++ -Wall -O2 -o try apply.cpp
  apply.cpp: In function `int main()':
  apply.cpp:24: Internal compiler error 980715.
  apply.cpp:24: Please submit a full bug report to 
`egcs-bugs@egcs.cygnus.com'.
  apply.cpp:24: See <URL: http://egcs.cygnus.com/faq.html#bugreport > for 
details.

Here is the apply.cpp source code:

#include <iostream.h>
#include <sys/types.h>

template <class Process, class Item, class SizeType>
void apply (Process f, Item data[], SizeType n);

template <class Process, class Item, class SizeType>
void apply (Process f, Item data[], SizeType n)
{
   for (SizeType i=0; i < n; i++)
     f(data[i]);
 }

template <class Item>
void triple (Item &i);

int main ()
{
   //int d[] = {0,4,5,7,8,3,2};
   char d[] = {'a', 'd', 't', 'g', 'k', 'j', 'o'};
   cout << "Before: ";
   for (int i=0; i < 7; i++) cout << d[i] << '\t';

   apply (triple<char>, d, 7);

   cout << "\n After: ";
   for (int i=0; i < 7; i++) cout << d[i] << '\t';
   cout << endl;
   return 0;
 }


template <class Item>
void triple (Item &i)
{
   i *= 3;
 }



More information about the Gcc-bugs mailing list