c++ - How to call a function using an argument supplied from the template function -
edit: clarify "t" called when casted. compiler knows , state function pointer takes argument of type int. supply null int pointer break loop because calling recursively. may bug in compiler.
i trying call function template function argument. assume possible call function without explicit casting not seem case. using vc2013.
template<typename t> void func(t t) { printf("calling func...\n"); if (t) { ((void(__cdecl*)(int))t)((int)nullptr); // explicit casting successful t ((int)nullptr); // compile error: ``term not evaluate function taking 1 arguments`` } } void main() { auto pe = func < int > ; auto pf = func < void(__cdecl*)(int) >; pf(pe); }
you have error func<int>
becomes:
void func(int t) { printf("calling func...\n"); if (t) { ((void(__cdecl*)(int))t)((int)nullptr); // bad casting t ((int)nullptr); // compile error: int not callable object } }
Comments
Post a Comment