This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
template function explicit instantiation
- From: Gokhan Kisacikoglu <kisa at centropolisfx dot com>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 03 Oct 2002 10:11:39 -0700
- Subject: template function explicit instantiation
- Organization: Centropolis Effects, LLC
- Reply-to: kisa at centropolisfx dot com
I am trying to instantiate a template function explicitly to pass as an
argument to another function, here's an example:
#include <iostream>
using namespace std;
typedef void * (_KMP_FN_)(void *);
template <class T>
void doIt( T *_t )
{
cerr << (*_t) << endl;
}
void doFn( _KMP_FN_ _fn )
{
int i = 5;
_fn(&i);
}
int main(void)
{
int i = 10;
doIt(&i);
doFn( (_KMP_FN_ *) doIt <int> );
return 0;
}
I tried instantiating doIt(int *) just to make sure that an instance of
the function can be found, though I expect the compiler to instantiate
the function automatically. Anyway, if anyone can figure out the syntax,
please let me know...
I am using gcc 3.2, This is the error:
t.cpp: In function `int main()':
t.cpp:29: no matches converting function `doIt' to type
`void*(*)(void*)'
t.cpp:8: candidates are: template<class T> void doIt(T*)
Thanks,
Gokhan