Please refer the code below:
typedef void (*TimerCallback)(int RequestID_in, void* AdditionalParameter_in);
class MyTimer
{
public:
MyTimer(){}
bool schedule( int Interval_in, TimerCallback TimerCallback_in, void* AdditionalParameter_in)
{
//some logic
return true;
}
};
namespace
{
template <class T>
void myTimerFunc(int RequestID_in, void* AdditionalParameter_in)
{
MyLogic<T>* pLogic = static_cast<MyLogic<T>*>(AdditionalParameter_in);
if(pLogic)
{
//do something
}
}
}
template <class T>
class MyLogic
{
public:
MyLogic(){}
void testMe()
{
MyTimer aTimer;
aTimer.schedule(10, myTimerFunc<T>, this);
}
};
int main()
{
MyLogic<int> myLogic;
myLogic.testMe();
}
I am using VC6 compiler and the compiler throws following error:
error C2664: 'schedule' : cannot convert parameter 2 from 'void (int,void *)' to 'void (__cdecl *)(int,void *)' None of the functions with this name in scope match the target type E:\test\BTest\BTest.cpp(46) : while compiling class-template member function 'void __thiscall MyLogic::testMe(void)'
I tested this code in Visual Studio 2008 and it works fine without any issues.
I know VC6 is an outdated compiler but my project source code(legacy) is still compiled with VC6.
Hence, any work around possible to make this code compile?