This is the mail archive of the gcc-bugs@gcc.gnu.org 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: Template function as an argument to a function


On Tue, 2 May 2000, mi60607 wrote:

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

I believe it is possible. 

> 
>   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.

This code works fine with gcc 2.95.2, so I think the bug is fixed.
  I do not know what version you are using, but I suggest you upgrade. 

Thank you for your bug report.

> 
> 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;
>  }
> 
> 


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