typedef bool (*my_function_f)(int, double);
typedef bool (__stdcall *my_function_f2)(int, double);
// ^^^^^^^^^
template class TFunction;
tem
This is because (*) means default calling convention, which is __cdecl
.
template<class R, class T0, class T1>
class TFunction<R(*)(T0,T1)>
{
typedef R (*func_type)(T0,T1);
};
is actually equal to
template<class R, class T0, class T1>
class TFunction<R(__cdecl *)(T0,T1)>
{
typedef R (__cdecl *func_type)(T0,T1);
};
which, of course, will not match an R(__stdcall *)(T0, T1)
on Win32 where __stdcall
is not ignored. If you want to partially specialize for function pointers then you will need a partial spec for every calling convention you want to accept.
No, this is by design. The calling convention is very much part of the function declaration, your template function uses the default calling convention. Which is not __stdcall unless you compile with /Gz. The default is /Gd, __cdecl.
The code compiles when you target x64 because it blissfully has only one calling convention.
Fix:
template<class R, class T0, class T1>
class TFunction<R (__stdcall *)(T0,T1)>
{
// etc..
};
You have not specialized your template for the stdcall case, i.e. you need
template<class R, class T0, class T1>
class TFunction<R(__stdcall *)(T0,T1)>
{
typedef R (*func_type)(T0,T1);
};
Not sure about the syntax, untested, but that should be the issue.