gpt4 book ai didi

c++ - 尝试使用函数填充线程 vector - 错误

转载 作者:行者123 更新时间:2023-11-28 00:54:58 26 4
gpt4 key购买 nike

我正在尝试填充 vector 线程;具有遍历目录的函数,但我遇到了问题

这是我的:

//create vector of threads
vector<thread> threads;

for(unsigned i=0; i < threadNum; ++i)
{
threads.push_back(thread(grep(arguments, r))); //best c++ 11
}

这是我得到的错误:

error c2440: '<function-style-cast>': cannot conver from 'void' to std::thread

谁能解释原因并给出答案?谢谢

编辑

grep是函数名

void grep(Arguments arguments, regex r){}

最佳答案

大概你是想说类似的话

threads.push_back(thread(grep, arguments, r));

甚至更好:

threads.emplace_back(grep, arguments, r);

关于c++ - 尝试使用函数填充线程 vector - 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11994439/

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