Sample code to reproduce the problem:
#include <iostream>
template< typename T, typename Func >
void action(Func T::* func)
{
T entry;
(entry.*func)();
}
struct A
{
void f()
{
std::cout << "A::f()" << std::endl;
}
};
int main()
{
action(&A::f);
return 0;
}
This code successfully compiles using MS VC++2008, with VC++2015 using vc140 toolset, but fails to compile when used in VC++2015 project with vc90 (VC++2008) toolset. Gives strange diagnostics of
cpptest.cpp(20): error C2664: 'action' : cannot convert parameter 1 from 'void (__thiscall A::* )(void)' to 'void (A::* )(void)'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Seems compiler looses __thiscall calling convention specifier when deducing type for Func. Tried to forcibly specify __thiscall in different parts of the code but had no success. Converting the whole project to vc14 toolset is not a way because of various dependencies and keeping it under the VS 2008 is an unlikely way. Any ideas to force compiler to understand such a construction?
Update
Changing code to
template< typename T, typename Func >
void action(Func func)
....
and calling to action< A >( &A::f ); works, but looks little ugly - I expect compiler to be able to deduce type for both template arguments (T and Func) automatically