dimanche 23 mai 2021

why does std::thread throws an error when it's asked to run an overloaded function?

below is the code i am running , it throws an error in the lines where i am passing overloaded function 'myfunc' in thread object t1 and t2 (also identified with a comment)

#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;
    }

The error statement:

Error 1: Error (active) E0289 no instance of constructor "std::thread::thread" matches the argument list arguments type are: (unknown-type,int)

Error 2: Error (active) E0289 no instance of constructor "std::thread::thread" matches the argument list arguments type are: (unknown-type,int,int)

Aucun commentaire:

Enregistrer un commentaire