Reputation: 225
In my C++ program I create two overloading function doSomething() and doSomething(int, int). My problem is that when I call async task by passing (async, doSomething, a, b) parameter the compiler gives "No Matching Function for call async" error. So guys how can I pass two arg doSomething(int, int) function under async task.
My Code:
void doSomething(){ // do some work}
void doSomething(int &a, int &b){ // do some work}
int main(){
int a = 34, b = 44;
auto f = std::async(std::launch::async, doSomething, std::ref(a), std::ref(b));
}
Upvotes: 1
Views: 146
Reputation: 556
The problem is in type deducing for "doSomething". Without specifying it's deduced as "void()" so you should explicitly specify different function type to use:
auto f = std::async<void(int&,int&)>(std::launch::async, doSomething, std::ref(a), std::ref(b));
Upvotes: 6