std :: thread ---没有匹配的构造函数

秋野野

所以,我有这段代码,应该作为一个单独的线程运行:

template<class Iterator>
void thread_launcher(Iterator start, Iterator fin, size_t sort_type) {
    // Blah blah
    mixed_sort<less<int>>(start, fin, sort_type);
    // blah blah
}

这段代码应该创建这个线程:

for (size_t sort_type = 2; sort_type!= 7; ++sort_type) {
    // blah
    t[sort_type] = thread(thread_launcher, copy.begin(), copy.end(), sort_type);
}

,其中t是的数组thread

问题是---当我尝试编译它时,出现以下错误:

main.cpp:245:32: error: no matching constructor for initialization of
      'std::__1::thread'
  ...= thread(thread_launcher, copy.begin(), copy.end(), sort_type);
       ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:349:9: note: 
      candidate template ignored: couldn't infer template argument '_Fp'
thread::thread(_Fp&& __f, _Args&&... __args)

我不明白我做错了什么,尽管这是我第一次使用多线程,更不用说了std::thread我应该怎么做才能解决这个问题?

阿米·塔沃里(Ami Tavory)

不确定是否没有所有细节,但令人惊讶的是您正在thread_launcher作为参数传递这不是功能,而是功能模板

考虑以下:

template<typename T>
void foo(T)
{

}


int main()
{
    thread t(foo<int>, 3);
    return 0;
}

在我看来,这很重要,但是当我将其更改为

thread t(foo, 3);

它无法建立。

然后,您可能希望将自己更改为

thread(
     thread_launcher<decltype(begin(copy))>, 
     begin(copy),
     end(copy), 
     sort_type)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

没有参数的std :: thread构造函数

来自分类Dev

没有匹配的构造函数,用于初始化'std :: thread'

来自分类Dev

vscode中的C ++:错误:没有匹配的构造函数来初始化'std :: thread'

来自分类Dev

C ++ 11多线程合并排序,错误为“没有构造函数'std :: thread'的实例与参数列表匹配”

来自分类Dev

在没有复制构造函数的对象的成员函数中启动 std::thread

来自分类Dev

没有合适的构造函数可以从void转换为std:thread

来自分类Dev

C ++ 11:为什么我会收到错误消息:调用std :: thread :: thread没有匹配函数?

来自分类Dev

std :: thread构造函数(变量数量)

来自分类Dev

std :: thread的构造和执行

来自分类Dev

通过(Args && ...)构造std :: thread

来自分类Dev

'std :: thread :: thread':没有重载函数需要7个参数

来自分类Dev

具有Qt的std :: thread

来自分类Dev

std :: thread构造函数传递指针和ref传递之间有区别吗?

来自分类Dev

std :: thread构造函数如何检测右值引用?

来自分类Dev

std :: thread通过引用传递调用复制构造函数

来自分类Dev

无法捕获由std :: thread构造函数引发的异常

来自分类Dev

std :: thread通过引用传递调用复制构造函数

来自分类Dev

创建没有复制构造函数的std :: vectors的std :: vector

来自分类Dev

错误C2280:'std :: thread :: thread(const std :: thread&)':尝试引用已删除的函数

来自分类Dev

C++11:Mac 上的 Clang 没有捕获 std::thread 函数抛出的异常?

来自分类Dev

错误:没有用于初始化“std::shared_ptr<uint8_t []>”的匹配构造函数

来自分类Dev

暂停std :: thread直到函数完成

来自分类Dev

std :: thread Args ...列表中的函数指针

来自分类Dev

std :: thread Args ...列表中的函数指针

来自分类Dev

可连接std :: thread的析构函数

来自分类Dev

用不同的参数函数运行std :: thread

来自分类Dev

在函数方法中使用std :: thread

来自分类Dev

显示 std::thread 函数传递的错误数据。

来自分类Dev

为什么std :: exception没有移动构造函数?

Related 相关文章

  1. 1

    没有参数的std :: thread构造函数

  2. 2

    没有匹配的构造函数,用于初始化'std :: thread'

  3. 3

    vscode中的C ++:错误:没有匹配的构造函数来初始化'std :: thread'

  4. 4

    C ++ 11多线程合并排序,错误为“没有构造函数'std :: thread'的实例与参数列表匹配”

  5. 5

    在没有复制构造函数的对象的成员函数中启动 std::thread

  6. 6

    没有合适的构造函数可以从void转换为std:thread

  7. 7

    C ++ 11:为什么我会收到错误消息:调用std :: thread :: thread没有匹配函数?

  8. 8

    std :: thread构造函数(变量数量)

  9. 9

    std :: thread的构造和执行

  10. 10

    通过(Args && ...)构造std :: thread

  11. 11

    'std :: thread :: thread':没有重载函数需要7个参数

  12. 12

    具有Qt的std :: thread

  13. 13

    std :: thread构造函数传递指针和ref传递之间有区别吗?

  14. 14

    std :: thread构造函数如何检测右值引用?

  15. 15

    std :: thread通过引用传递调用复制构造函数

  16. 16

    无法捕获由std :: thread构造函数引发的异常

  17. 17

    std :: thread通过引用传递调用复制构造函数

  18. 18

    创建没有复制构造函数的std :: vectors的std :: vector

  19. 19

    错误C2280:'std :: thread :: thread(const std :: thread&)':尝试引用已删除的函数

  20. 20

    C++11:Mac 上的 Clang 没有捕获 std::thread 函数抛出的异常?

  21. 21

    错误:没有用于初始化“std::shared_ptr<uint8_t []>”的匹配构造函数

  22. 22

    暂停std :: thread直到函数完成

  23. 23

    std :: thread Args ...列表中的函数指针

  24. 24

    std :: thread Args ...列表中的函数指针

  25. 25

    可连接std :: thread的析构函数

  26. 26

    用不同的参数函数运行std :: thread

  27. 27

    在函数方法中使用std :: thread

  28. 28

    显示 std::thread 函数传递的错误数据。

  29. 29

    为什么std :: exception没有移动构造函数?

热门标签

归档