1

我试图弄清楚 Cereal 序列化是如何工作的,所以我阅读了文档(我发现它有点缺乏 imo)并试图重现他们在那里的代码:

#include <sstream>
#include <archives/binary.hpp>

struct MyData
{
  int x, y, z;

  // This method lets cereal know which data members to serialize
  template<class Archive>
  void serialize(Archive & archive)
  {
    archive( x, y, z ); // serialize things by passing them to the archive
  }
};

int main()
{
    std::stringstream ss; // any stream can be used

     {
       cereal::BinaryOutputArchive oarchive(ss); // Create an output archive

       MyData m1, m2, m3;
       oarchive(m1, m2, m3); // Write the data to the archive
     } // archive goes out of scope, ensuring all contents are flushed

     {
       cereal::BinaryInputArchive iarchive(ss); // Create an input archive

       MyData m1, m2, m3;
       iarchive(m1, m2, m3); // Read the data from the archive
     }

    return 0;
}

我直接从 Cereal 的文档中复制了代码,但我不断收到错误消息:

type 'cereal::BinaryInputArchive' does not provide a call operator

4

1 回答 1

0

显然我没有正确地包括解决问题的库。

于 2019-01-04T16:25:43.870 回答