gpt4 book ai didi

c++ - 如何通过调用类中的函数来创建线程?

转载 作者:行者123 更新时间:2023-11-27 23:47:51 26 4
gpt4 key购买 nike

<分区>

假设有

class concurr{
public:

double arr[100];
void func1(vector<vector<double>> data,int x);
double func2(vector<vector<double>> data);
}

这样 func2 接受“数据”并将其提供给 func1 相同的“数据”但 x 的数量从 0 到 100 不等。然后在 func1 中,它计算一些东西以及它的 double 值出来,为 arr[x] 填充所以基本上,func2 看起来一般像

    double concurr::func2(vector<vector<double>> data){

thread threads[100];
for (int x = 0; x < 100; x++){
threads[x] = thread(concurr::func1,data,x); // this line is where the problem is
}
for (auto& th : threads){
th.join();
}
// ..... does something with the arr[100].... to come up with double = value
return value;
}

没有多线程部分,代码运行良好,只是添加了多线程部分,当我尝试编译时,它说“对非静态成员函数的引用必须是 叫“

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com