C++ 传递'成员的参考;这';转换为std::thread的参数
我需要编写一个不属于类C++ 传递'成员的参考;这';转换为std::thread的参数,c++,qt,C++,Qt,我需要编写一个不属于类MainWindow(这是一个Qt项目)的函数,以便它可以在线程中使用,但我还需要它在线程中使用MainWindow的成员。以下是我编写的代码: void nameChange(TMAPI *tmapi) { tmapi->writeString(0x001bbbc2c, qPrintable(n)); } void MainWindow::on_button_clicked() { std::thread id(nameChange, this-&
MainWindow
(这是一个Qt项目)的函数,以便它可以在线程中使用,但我还需要它在线程中使用MainWindow
的成员。以下是我编写的代码:
void nameChange(TMAPI *tmapi) {
tmapi->writeString(0x001bbbc2c, qPrintable(n));
}
void MainWindow::on_button_clicked() {
std::thread id(nameChange, this->tmapi);
id.join();
}
我从中得到两个错误(它们是相同的错误,但指向文件
中的不同代码行):
当我传入当前对象(
这个
的)tmapi实例时,如何获得第一种工作方式?谢谢 nameChange
采用TMAPI*
。您正试图向其传递一个TMAPI
。因此出现了一个超级神秘的错误:
error: no type named 'type' in 'class std::result_of<void (*(TMAPI))(TMAPI*)>
nameChange
采用TMAPI*
。您正试图向其传递一个TMAPI
。因此出现了一个超级神秘的错误:
error: no type named 'type' in 'class std::result_of<void (*(TMAPI))(TMAPI*)>
这是一个TMAPI,没有指针。啊,你抓住我了。我将参数更改为
&this->tmapi
,现在可以工作了。谢谢这是一个TMAPI,没有指针。啊,你抓住我了。我将参数更改为&this->tmapi
,现在可以工作了。谢谢
error: no type named 'type' in 'class std::result_of<void (*(TMAPI))(TMAPI*)>
std::thread id(nameChange, &this->tmapi);