关于void *参数的错误c3867 [英] The error c3867 about a void* parameter

查看:137
本文介绍了关于void *参数的错误c3867的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vs2005有一个线程类

I have a thread class at vs2005

m_hThread = (HANDLE)_beginthreadex(NULL,0, CThreadClass::start_address, this, 0,  &m_Thraddr)



有一个错误C3867:


There is a error C3867:

"CThreadClass::start_address": function lost function list.







Unsigned CThreadClass::start_address(void* obj)
{ 
  return FALSE; 
}





你能告诉我如何解决这个错误吗?



我来自博客 http://www.cppblog.com/的裁判API / archive / 2011/03/11 / 141563.html [ ^ ]



但我不想要一个静态类函数。



Could you tell me how can I cover this error?

I referee from the blog http://www.cppblog.com/API/archive/2011/03/11/141563.html[^]

But I don't want a static class function.

推荐答案

您不能将指向成员函数的指针作为例程传递给_beginthread()函数。该函数需要一个指向全局或静态函数的指针。
You can't pass a pointer to a member function as the routine to the _beginthread() function. The function requires a pointer to a global or static function.


线程函数必须是静态的。但是你可以使用一个静态包装函数,在向你的类传递指针时调用非静态成员函数:

Thread functions must be static. But you can use a static wrapper function that calls a non-static member function when passing a pointer to your class:
CThreadClass
{
    // ...
    void start_thread();
private::
    // Static thread function
    unsigned __stdcall start_address(void* obj);
    // Non-static function called from static version
    unsigned thread_func();
};




void CThreadClass::start_thread()
{
    m_hThread = (HANDLE)_beginthreadex(NULL,0, &CThreadClass::start_address, this, 0,  &m_Thraddr);
}

// Static thread function
unsigned CThreadClass::start_address(void* obj)
{
    CThreadClass *p = (CThreadClass *)obj;
    return p->thread_func();
}

// Non-static function called from static thread function
unsigned CThreadClass::thread_func()
{
    // Do your work here using the class's member variables and functions
    return FALSE;
}


这篇关于关于void *参数的错误c3867的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆