mongocxx document steam 使用 time_t 转的 long long,在 mac 下可以编译运行,在 docker 的 ubuntu 里报错 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xzpjerry731
V2EX    MongoDB

mongocxx document steam 使用 time_t 转的 long long,在 mac 下可以编译运行,在 docker 的 ubuntu 里报错

  •  
  •   xzpjerry731 2018-03-11 13:55:50 +08:00 4618 次点击
    这是一个创建于 2771 天前的主题,其中的信息可能已经有所发展或是发生改变。

    报错都发生在 bsoncxx ::builder::stream::document{} << {某个从 time_t 通过(long long)转型的变量}

    提示 error: call of overloaded 'append(long long int)' is ambiguous

    请问是什么问题?

    第 1 条附言    2018-03-12 00:24:47 +08:00

    @gnaggnoyil #1 不好意思,之前发帖的时候太匆忙了没有表述到位。大致可以总结成下面这种情况,只要用了time_t转成的long long就不行(在ubuntu环境下)

    time_t now = time(0); auto cOnfig= bsoncxx::builder::stream::document{} << "last_studied@" << (long long)(now) // 第47行 << bsoncxx::builder::stream::finalize; 

    但是下面这种情况就没有编译报错

    auto cOnfig= bsoncxx::builder::stream::document{} << "last_studied@" << (long long)(946684800) << bsoncxx::builder::stream::finalize; 

    具体的编译错误如下(可以确定都是同样内容的编译错误,除了对应的行数不同):

    g++ -c -std=c++11 -g jobPool.cpp -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/bsoncxx/v_noabi -I/usr/local/include/libbson-1.0 In file included from /usr/local/include/bsoncxx/v_noabi/bsoncxx/builder/stream/key_context.hpp:20:0, from /usr/local/include/bsoncxx/v_noabi/bsoncxx/builder/stream/document.hpp:18, from jobPool.h:15, from jobPool.cpp:4: /usr/local/include/bsoncxx/v_noabi/bsoncxx/builder/stream/value_context.hpp: In instantiation of 'typename std::enable_if<(! std::is_convertible<T, std::function<void(bsoncxx::v_noabi::builder::stream::single_context)> >::value), base>::type bsoncxx::v_noabi::builder::stream::value_context<base>::operator<<(T&&) [with T = long long int; base = bsoncxx::v_noabi::builder::stream::key_context<>; typename std::enable_if<(! std::is_convertible<T, std::function<void(bsoncxx::v_noabi::builder::stream::single_context)> >::value), base>::type = bsoncxx::v_noabi::builder::stream::key_context<>]': jobPool.cpp:47:58: required from here /usr/local/include/bsoncxx/v_noabi/bsoncxx/builder/stream/value_context.hpp:70:9: error: call of overloaded 'append(long long int)' is ambiguous _core->append(std::forward<T>(t)); 
    3 条回复    2018-03-12 05:06:35 +08:00
    gnaggnoyil
        1
    gnaggnoyil  
       2018-03-11 17:28:42 +08:00   1
    没看懂.`bsoncxx::builder::stream::document`的`operator<<`不是只能接受 string,bson 的 document 和`bsoncxx::builder::stream::finalize`的吗.哪儿有接受 long long 的?LZ 能不能发一下详细的编译错误?
    xzpjerry731
        2
    xzpjerry731  
    OP
       2018-03-12 00:27:36 +08:00
    @gnaggnoyil #1 append 更多信息了,谢谢你的回复!
    xzpjerry731
        3
    xzpjerry731  
    OP
       2018-03-12 05:06:35 +08:00
    @gnaggnoyil #1 问题解决了,受到你的启发,我把(long long)换成了 bsoncxx::types::b_int64{}, 然后就可以了。估计 mac 下的编译器有考虑到把原生类型转换成 bsoncxx 的类型,但是 ubuntu 下的没有
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1158 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 17:48 PVG 01:48 LAX 10:48 JFK 13:48
    Do have faith in what you're doing.
    ubao 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