没有匹配的构造函数,用于"std :: thread"的初始化 [英] no matching constructor for initialization of 'std::thread'
本文介绍了没有匹配的构造函数,用于"std :: thread"的初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在研究一个相当简单的工具:并发的 for
循环结构,该结构接受输入元素的列表,输出向量以及从输入元素中计算输出元素的函数.
I have been working on a rather simple facility: a concurrent for
loop construct that takes a list of input elements, an output vector, and a function that computes output elements out of input elements.
我有一个无法编译的代码段:
I have this snippet that does not compile:
template<class In, class Out>
void thread_do(net::coderodde::concurrent::queue<In>& input_queue,
Out (*process)(In in),
std::vector<Out>& output_vector)
{
// Pop the queue, process, and save result.
...
}
for (unsigned i = 0; i < thread_count; ++i)
{
thread_vector.push_back(std::thread(thread_do,
input_queue,
process,
output_vector));
}
我使用 -std=c++14
.
I use -std=c++14
.
./concurrent.h:129:45: error: no matching constructor for initialization of 'std::thread'
thread_vector.push_back(std::thread(thread_do,
^ ~~~~~~~~~~
但是,我不知道如何解决它.尝试在 &
之前添加 thread_do
/添加 <In, Out>
,但无济于事.
However, I have no idea how to fix it. Tried to prepend &
to the thread_do
/appending <In, Out>
, yet no to avail.
推荐答案
您需要实例化函数:
thread_vector.push_back(std::thread(thread_do<In, Out>, // you need to instantiate your template function
std::ref(input_queue), // pass parameters by ref
std::ref(process), // - // -
std::ref(output_vector))// - // -
);
这篇关于没有匹配的构造函数,用于"std :: thread"的初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文