so i've gotten comfortable storing template function pointers in map containers now, mainly as a method of templating a function that returns a new instance of the templated object and storing that function pointer in a map to be called when given a corresponding string index (that was a mouthful). my question lies with using the template function pointers. the only reason this seems to work is because neither the return type or the parameters are of the type template parameter. It looks like this:
template<class T>
base * createT() {return new T;}
where T should be a class derived from base. now i can make a function pointer that works fine
base*(*funcptr)() = &createT<derived>;
but let's say i wanted to setup something like this:
template <class returnType, class T>
returnType * createT() { return new T;}
what would the declaration of a function pointer look like for this function?
You can't have a pointer to a function template, only to a function. So really the templating is irrelevant; you'd do something like
A *(*funcptr)() = &createT<A,B>;
Demo: http://ideone.com/NoHYS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With