且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将void(__thiscall MyClass :: *)(void *)转换为void(__cdecl *)(void *)指针

更新时间:2021-11-18 00:56:05

您不能。

静态函数(不是静态成员函数,而是一个***函数)。

You should use a static function instead (not a static member function, but a free function).

// IThread.h
class IThread
{
public:
    void BeginThread();
    virtual void ThreadMain() = 0;
};

// IThread.cpp
extern "C"
{
    static void __cdecl IThreadBeginThreadHelper(void* userdata)
    {
        IThread* ithread = reinterpret_cast< IThread* >(userdata);
        ithread->ThreadMain();
    }
}
void IThread::BeginThread()
{
    m_ThreadHandle = _beginthread(
                     &IThreadBeginThreadHelper,
                     m_StackSize, reinterpret_cast< void* >(this));
}