初学 c++的 std::future,请大佬解惑.... - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Iain
V2EX    C

初学 c++的 std::future,请大佬解惑....

  •  1
     
  •   Iain 2019-04-02 22:39:11 +08:00 3103 次点击
    这是一个创建于 2443 天前的主题,其中的信息可能已经有所发展或是发生改变。

    std::future 可以这样直接定义吗?

    #include <iostream></iostream>

    #include <future></future>

    int main() {

    std::future<int> feature; return 0; 

    }

    10 条回复    2019-04-04 13:42:55 +08:00
    wutiantong
        1
    wutiantong  
       2019-04-03 10:52:23 +08:00   1
    可以

    Default constructor. Constructs a std::future with no shared state. After construction, valid() == false.

    https://en.cppreference.com/w/cpp/thread/future/future
    Iain
        2
    Iain  
    OP
       2019-04-03 12:41:40 +08:00
    @wutiantong 可是为什么我的编译器会报错,
    aggregate 'std::future<int> feature' has incomplete type and cannot be defined
    用其他电脑测试无错...也设置了 g++11 支持 可以提供一下解决思路吗 ?
    wutiantong
        3
    wutiantong  
       2019-04-03 13:36:45 +08:00   1
    @Iain
    1. 检查你的编译器是否支持 c++11 或以上
    2. 检查你编译时是否打开了 c++11 或以上的开关 ( -std=c++11 )
    3. 确认代码里加了头文件 #include <future>
    Iain
        4
    Iain  
    OP
       2019-04-03 13:57:21 +08:00
    @wutiantong
    我好像发现问题所在了,请问 mingw 的 thread model (有 posix、和 win32 ) 这个是否影响 c++11 新特性呢?
    mingw 4.9.2 posix 成功编译
    mingw 6.3.0 win32 编译失败
    wutiantong
        5
    wutiantong  
       2019-04-03 14:50:09 +08:00   1
    @Iain 是这个问题,看这里就知道了: https://stackoverflow.com/a/30390278/6947776
    Iain
        6
    Iain  
    OP
       2019-04-03 18:37:05 +08:00
    @wutiantong 您好,十分感谢您百忙之中为我解惑。
    我又遇一个问题...
    mingw-w64 两种 thread model ( posix /win32 ) 通过 makefile 生成的 dll 文件为何相差很大,一个 148kb ( win32 )一个 501kb ( posix ),而且通过 System.load 调用只能识别 win32 生成的 dll,对于 posix 模式生成的 dll 显示未找到
    wutiantong
        7
    wutiantong  
       2019-04-04 09:49:35 +08:00   1
    @Iain 看起来这个项目应该能帮到你: https://github.com/meganz/mingw-std-threads
    Iain
        8
    Iain  
    OP
       2019-04-04 10:21:28 +08:00
    @wutiantong 感谢你的回复
    我分别使用 mingw-w64 8.1.0、6.3.0、5.4.0、4.8.1 都是 posix thread model ;只有 5.4.0 版本生成的 dll 可以识别。
    wutiantong
        9
    wutiantong  
       2019-04-04 10:46:16 +08:00   1
    @Iain 找不到 dll 的问题多半还是跟你的编译环境和流程有关,但我没接触过 mingw 这方面的开发,爱莫能助啦
    Iain
        10
    Iain  
    OP
       2019-04-04 13:42:55 +08:00
    @wutiantong
    问题目前暂时是解决了,很感谢您的帮助!
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     909 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 22:08 PVG 06:08 LAX 14:08 JFK 17:08
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86