无效使用不完整类型'std :: future

问题描述 投票:0回答:1

我有一个错误

无效使用不完整类型'class std :: future

我使用了g ++ -std = c ++ 17

我的代码:

#include <iostream>
#include <iterator>
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include <algorithm>
#include <numeric>
#include <future>
#include <future>

int sumTwoVectors(const vector<int>& one,
                  const vector<int>& two) {
    future<int> f = async([&] {
        return accumulate(begin(one), end(one), 0);
    });
    int result = accumulate(begin(two), end(two), 0);
    return  result + f.get();
}

int main() {
    cout << sumTwoVectors({1, 1, 1, 1}, {3, 3, 3});
}

我正在使用Win8.1

g ++ -v

COLLECT_GCC = C:\ Users \ alex \ gcc \ bin \ g ++。exeCOLLECT_LTO_WRAPPER = c:/ users / alex / gcc / bin /../ libexec / gcc / i686-pc-mingw32 / 9.2.0 / lto-wrapper.exe目标:i686-pc-mingw32配置为:../gcc-9.2.0-mingw/configure --host = i686-pc-mingw32 --build = x86_64-unknown-linux-gnu --target = i686-pc-mingw32 --prefix = / home /gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/9.2.0 --with-gcc --with-gnu-as --with-gnu-ld --with-cloog = / home / gfortran / gcc-home / binary / mingw32 / native / x86_32 / cloog --with-gmp = / home / gfortran / gcc-home / binary / mingw32 / native / x86_32 / gmp --with-mpfr = / home / gfortran / gcc- home / binary / mingw32 / native / x86_32 / mpfr --with-mpc = / home / gfortran / gcc-home / binary / mingw32 / native / x86_32 / mpc --with-diagnostics-color = auto --enable-cloog- backend = isl --with-sysroot = / home / gfortran / gcc-home / binary / mingw32 / cross / x86_32 / gcc / 9-20190310 --disable-shared --disable-nls --disable-tls --disable- libgcc2 --disable-win32-registry --enable-build-with-cxx --enable-libquadmath-support --enable-libquadmath --enable-languages = c,c ++,fortran --disable-checking --enable-libgomp --enable-threads = win32 --enable-lto --enable-static --enable-shared = lto-plugin --enable-plugins --enable-ld = yes线程模型:win32

c++ multithreading g++
1个回答
0
投票

您是否忘记了包含<future>?它可以在我的机器(win10,g ++ 8.1.0)和compiler explorer上运行。如果这样做没有帮助,请在文件的部分添加#include-s

© www.soinside.com 2019 - 2024. All rights reserved.