This is the mail archive of the gcc-help@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]
Other format: [Raw text]

template function explicit instantiation


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


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