报错都发生在 bsoncxx ::builder::stream::document{} << {某个从 time_t 通过(long long)转型的变量}
提示 error: call of overloaded 'append(long long int)' is ambiguous
请问是什么问题?
@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));
1 gnaggnoyil 2018-03-11 17:28:42 +08:00 ![]() 没看懂.`bsoncxx::builder::stream::document`的`operator<<`不是只能接受 string,bson 的 document 和`bsoncxx::builder::stream::finalize`的吗.哪儿有接受 long long 的?LZ 能不能发一下详细的编译错误? |
![]() | 2 xzpjerry731 OP @gnaggnoyil #1 append 更多信息了,谢谢你的回复! |
![]() | 3 xzpjerry731 OP @gnaggnoyil #1 问题解决了,受到你的启发,我把(long long)换成了 bsoncxx::types::b_int64{}, 然后就可以了。估计 mac 下的编译器有考虑到把原生类型转换成 bsoncxx 的类型,但是 ubuntu 下的没有 |