【发布时间】:2020-03-02 20:39:03
【问题描述】:
我有一个错误
不完整类型 '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++.exe COLLECT_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/clog --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
【问题讨论】:
-
Works fine 当您添加所有缺少的包含时。
-
你开启C++11支持了吗?
-
@alcoder 您显示的代码无法编译,但错误消息将非常不同。请显示(完整!)您实际验证的代码以提供错误消息,并以minimal reproducible example 的形式。
-
@alcoder 您最近的编辑并没有解决我在之前的评论中提到的问题。同样,请在发布时发布您实际测试过的代码完全。
标签: c++ multithreading g++