【发布时间】:2019-03-16 21:27:19
【问题描述】:
我认为这会更简单,但尝试了以下多种变体后,我无法编译此代码
#include <thread>
#include <algorithm>
#include <future>
int main()
{
std::vector<int> vec(1000000, 0);
std::future<int> x = std::async(std::launch::async, std::accumulate, vec.begin(), vec.end(), 0);
}
error: no matching function for call to 'async(std::launch, <unresolved overloaded function type>, std::vector<int>::iterator, std::vector<int>::iterator, int)'
我错过了什么?
【问题讨论】:
-
std::accumulate 是一个模板。无法推断参数类型。需要指定每个。
标签: c++ concurrency