小编abd*_*eem的帖子

为什么 std::thread 在被要求运行重载函数时会抛出错误?

下面是我正在运行的代码,它在我在线程对象 t1 和 t2 中传递重载函数“myfunc”的行中引发错误(也用注释标识)

#include<iostream>
#include<thread>
using namespace std;

    void  myfunc(int x)
        {
            cout << x << endl;
        }

    void  myfunc(int  x,int y)
    
    {
        
        cout << x << " " << y << endl;
    }

    int main()
    {
    
        thread t1(myfunc,1);//error here
        thread t2(myfunc, 1,2);//error here
        
        t1.join();
        t2.join();
        return 0;
    }
Run Code Online (Sandbox Code Playgroud)

错误声明:

错误 1: 错误(活动)E0289 没有构造函数的实例“std::thread::thread”匹配参数列表参数类型是:(unknown-type,int)

错误 2: 错误(活动)E0289 没有构造函数“std::thread::thread”的实例匹配参数列表参数类型是:(unknown-type,int,int)

c++ multithreading visual-c++ c++11

2
推荐指数
1
解决办法
73
查看次数

标签 统计

c++ ×1

c++11 ×1

multithreading ×1

visual-c++ ×1