使用这段代码,我得到了错误:
错误 1 错误 C2064:术语未计算为采用 1 个参数的函数 c:\program files (x86)\microsoft Visual Studio 11.0\vc\include\featured 1152 1 Pipeline
class PipelineJob {
private:
std::thread *thread;
void execute(PipelineJob* object);
public:
void execute(PipelineJob* object)
{
}
PipelineJob()
{
this->thread = new std::thread(&PipelineJob::execute, this);
}
};
我尝试了很多变体,现在有人如何解决这个问题吗?
为了简单起见,删除模板和指针,这或多或少是您想要的:
class PipelineJob
{
private:
std::thread thread_;
void execute(PipelineJob* object) { ..... }
public:
PipelineJob()
{
thread_ = std::thread(&PipelineJob::execute, this, this);
}
~PipelineJob() { thread_.join(); }
};
注意this
被传递两次std::thread
构造函数:一次用于成员函数的隐式第一个参数,第二个用于可见参数PipelineJob* object
的成员函数。
If your execute
成员函数不需要外部PipelineJob
指针,那么你需要类似的东西
class PipelineJob
{
private:
std::thread thread_;
void execute() { ..... }
public:
PipelineJob()
{
thread_ = std::thread(&PipelineJob::execute, this);
}
~PipelineJob() { thread_.join(); }
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)