线程或类错误

Thread or class error c++11

本文关键字:错误 线程      更新时间:2023-10-16

当我尝试用g++ -std=c++11 -pthread编译以下代码时,我得到以下错误,不知道为什么。

#include<thread>
using namespace std;
void test (){
}
int main () {
    thread t1 (test);
    t1.join;
    return 0;
}

8:9: error: statement不能解析重载函数的地址t1.join;

您在调用join时缺少圆括号:

t1.join();
//     ^^

现场演示