Assign a function pointer using template method? -
consider utility class below:
it contain lots of factory methods same signature int function(int a, int b);
utility.h
class utility { public: template<typename t, typename a, typename b> static int get_function(t% function, int% number) { function = (t) add; number = 10; return 0; } static int add (int a, int b) { return a+b; } };
this contains template method (get_function()) assign function pointers factory methods available in utility
class.
main.cpp
typedef int (__stdcall *fp) (int a, int b); ref class fpclass { public: static fp fp; static int number; static void apply_function() { utility::get_function<fp, int, int>(fpclass::fp, number); cout << fpclass::fp(25, 45); } }; void main() { fpclass::apply_function(); }
what want achieve is, assign function pointer (fpclass::fp
) template method (utility:get_function
).
but function pointer parameter not modified (always null) called function (utility:get_function
). why that?
Comments
Post a Comment