[英]Cannot use thread constructor
我一直在尝试学习如何多线程,但是我无法正确创建线程对象。 我有一个带有名为task的函数的对象,但是当我添加函数和参数时,它表示构造函数不接受它。 顺便说一句,即时通讯使用Visual Studio作为我的IDE。
这是我的主文件:
#include <iostream>
#include <thread>
#include "Task.h"
using namespace std;
int main(int argc, char** argv)
{
Task t;
thread t1(t.task, 1);
t1.join;
return 0;
}
任务对象的类:
#include "Task.h"
#include <iostream>
using namespace std;
Task::Task()
{
}
Task::~Task()
{
}
void Task::task(int x) {
cout << "In Thread " << x << '\n';
}
错误: Error: no instance of constructor"std::thread::thread" matches the argument list argument types are: (<error-type>, int)
更新:所以我放入thread t1(&Task::task, &t, 1);
并摆脱了t1.join
,但是现在我遇到了一个新问题。 该程序将编译并运行,但是在运行时,它将在控制台中显示“ In Thread 1”,然后出现另一个窗口,显示:
Debug Error!
abort() has been called
(Press retry to debug the application)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.