首页 > 解决方案 > 不完整类型 'class std::promise 的无效使用' 使用 arm-linux-gnueabi-g++-5 编译时出错

问题描述

使用 arm-linux-gnueabi-g++-5 filename.cpp -std=c++11 为 arm 编译以下代码时出现错误

#include <iostream>
#include <thread>
#include <future>

void initiazer(std::promise<int> * promObj)
{
    std::cout<<"Inside Thread"<<std::endl;     promObj->set_value(35);
}

int main()
{
    std::promise<int> promiseObj;
    std::future<int> futureObj = promiseObj.get_future();
    std::thread th(initiazer, &promiseObj);
    std::cout<<futureObj.get()<<std::endl;
    th.join();
    return 0;
}

错误 :

test.cpp:在函数'void initiazer(std::promise*)'中:test.cpp:10:55:错误:不完整类型'class std::promise'的无效使用std::cout<<"Inside Thread" <set_value(35); ^ 在 test.cpp:4:0 中包含的文件中:/usr/arm-linux-gnueabi/include/c++/5/future:124:11:注意:“class std::promise”类承诺的声明;^ test.cpp:在函数'int main()'中:test.cpp:15:23:错误:聚合'std::promise promiseObj'类型不完整,无法定义std::promise promiseObj;^ test.cpp:16:22: 错误:变量 'std::future futureObj' 具有初始化程序但类型不完整 std::future futureObj = promiseObj.get_future();

标签: c++11arm

解决方案


推荐阅读