2

公式の MongoDB C++ チュートリアルを実行しようとしたときに、理解できないエラーが発生しました。次のコードは、Web サイトから直接取得されます。

#include <chrono>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/types.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>

using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::open_document;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::finalize;

int main()
{
//...
    bsoncxx::document::value restaurant_doc = document{}
        << "address" << open_document << "street"
//...
        << bsoncxx::types::b_date{std::chrono::milliseconds{12323}}
//...
        << "restaurant_id" << "41704620"
        << finalize;

そして、GCC (v6.1.1) から得られるエラーは次のようになります。

insert.cpp: In function ‘int main()’:
insert.cpp:36:65: error: no matching function for call to     ‘bsoncxx::v_noabi::types::b_date::b_date(<brace-enclosed initializer list>)’
   << bsoncxx::types::b_date{std::chrono::milliseconds{12323}}

In file included from /usr/include/bsoncxx/v_noabi/bsoncxx/builder/core.hpp:26:0,
                 from /usr/include/bsoncxx/v_noabi/bsoncxx/builder/stream/document.hpp:17,
                 from insert.cpp:3:
/usr/include/bsoncxx/v_noabi/bsoncxx/types.hpp:306:14: note: candidate: bsoncxx::v_noabi::types::b_date::b_date(const time_point&)
     explicit b_date(const std::chrono::system_clock::time_point& tp)
              ^~~~~~

chrono::milliseconds中括弧の代わりに括弧で初期化しようとしましたが、GCC は、利用可能なbsoncxx::types::b_dateコンストラクターと私が提供しているものとの間の型の不一致について、より明確に不平を言いました。また、 MongoDB C++11 Driver docschrono::system_clock::time_pointに従って、同じ番号で初期化してフィードしようとしましたが、それでも不一致が発生しました。

だから...チュートリアルの資料がうまくいかない理由がわかりません。また、C ++の型付け、テンプレート、またはブレース初期化子リストを完全に理解していません。また、私が抱えている問題に特化したチュートリアルを喜んで実行したいと思いますが、Google で何を検索すればよいかさえわかりません。知識のギャップが広すぎる。=P

したがって、どんな助けでも大歓迎です。=)

4

1 に答える 1