如何将 void (__thiscall MyClass::* )(void *) 转换为 void (__cdecl *)(void *) 指针
我想构建一个可以隐藏线程创建的“IThread”类。子类实现“ThreadMain”方法并使其自动调用,看起来像这样:
class IThread
{
public:
void BeginThread();
virtual void ThreadMain(void *) PURE;
};
void IThread::BeginThread()
{
//Error : cannot convert"std::binder1st<_Fn2>" to "void (__cdecl *)(void *)"
m_ThreadHandle = _beginthread(
std::bind1st( std::mem_fun(&IThread::ThreadMain), this ),
m_StackSize, NULL);
//Error : cannot convert void (__thiscall* )(void *) to void (__cdecl *)(void *)
m_ThreadHandle = _beginthread(&IThread::ThreadMain, m_StackSize, NULL);
}
我已经搜索过但无法弄清楚。有人做过这样的事吗?还是我走错路了? TIA
I want to build a "IThread" class which can hide the thread creation. Subclass implements the "ThreadMain" method and make it called automatically which seems like this:
class IThread
{
public:
void BeginThread();
virtual void ThreadMain(void *) PURE;
};
void IThread::BeginThread()
{
//Error : cannot convert"std::binder1st<_Fn2>" to "void (__cdecl *)(void *)"
m_ThreadHandle = _beginthread(
std::bind1st( std::mem_fun(&IThread::ThreadMain), this ),
m_StackSize, NULL);
//Error : cannot convert void (__thiscall* )(void *) to void (__cdecl *)(void *)
m_ThreadHandle = _beginthread(&IThread::ThreadMain, m_StackSize, NULL);
}
I have searched around and cannot figure it out. Is there anybody who did such thing? Or I am going the wrong way? TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。
您应该使用静态函数(不是静态成员函数,而是自由函数)。
You can't.
You should use a static function instead (not a static member function, but a free function).