在c ++中运行类成员函数的线程 [英] run threads of class member function in c++

查看:181
本文介绍了在c ++中运行类成员函数的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说。
以下是我的代码框架。

As the title says. The following is my code skeleton.

class CLASS
{
public:
    void A();
private:
    DWORD WINAPI B(LPVOID);
};

void CLASS::A()
{
    DWORD (WINAPI CLASS::*thread)(LPVOID) = &CLASS::B;
    ...
    CreateThread(NULL, 0, thread, &arg, 0, NULL);
    ...
}

函数B需要CLASS的成员变量。 br>
但是我编译时出现错误代码。

无法将参数3从'DWORD(__stdcall CLASS :: *)(LPVOID)'转换为' LPTHREAD_START_ROUTINE或类似内容。

我不知道在英语环境中是否相同。

the function B needs CLASS's member variables.
But I've got an error code when I compiled this.
It's " can't convert argument 3 from 'DWORD (__stdcall CLASS::* )(LPVOID)' to 'LPTHREAD_START_ROUTINE' " or something like that.
I don't know if it is the same in the english environment.

可以任何人

推荐答案

请注意,如果你的编译器不支持std :: thread ):

Seriously, use std::thread (or boost::thread if your compiler doesn't support it yet):

class CLASS
{
public:
    void A();
private:
    void B(your args go here);
};

void CLASS::A()
{
    boost::thread(&CLASS::B, this, your args go here);
}

这篇关于在c ++中运行类成员函数的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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