0

I'm trying to pass the function countVocals() (which returns an integer) to a vector of future but I'm getting this issue:

'No matching function for call to async:'
candidate template ignored

How can I fix it?

I have tried both with the following syntax and with a lambda expression but I get the same issue

int countVocals(std::string const &fileName, int &found);
std::vector<int> vocals(argc-1, 0);
std::vector<std::future<int>> futures(argc-1);

for (int i = 1; i < argc; i++) {
    futures.push_back(std::async(countVocals, std::string(argv[i]), vocals.at(i-1)));
Richard Chambers
  • 16,643
  • 4
  • 81
  • 106

1 Answers1

1

countVocals expects a reference, so you need to explicitly pass a reference to st::async:

futures.push_back(std::async(countVocals, std::string("Bla"), std::ref(vocals.at(i))));
                                                              ^^^^^^^^
Mike van Dyke
  • 2,724
  • 3
  • 16
  • 31