4

我想在名为 theia 的库中序列化一个 Reconstruction 类。Reconstruction 类确实有一个序列化函数:

friend class cereal::access;
  template <class Archive>
  void serialize(Archive& ar) {  // NOLINT
    ar(next_track_id_,
       next_view_id_,
       view_name_to_id_,
       views_,
       tracks_);
  }

已经到位的序列化工作正常,如下所示:

Reconstruction estimated_reconstruction;

[...]
std::ofstream output_writer(output_file, std::ios::out | std::ios::binary);
cereal::PortableBinaryOutputArchive output_archive(output_writer);
 output_archive(estimated_reconstruction);

但是当我将它更改为 XMLOutputArchive(添加必要的#include)时,它不再起作用了!

Reconstruction estimated_reconstruction;
[...]

std::ofstream output_writer(output_file, std::ios::out);
cereal::XMLOutputArchive output_archive(output_writer);
output_archive(estimated_reconstruction);

错误如下:

[...]

error: static assertion failed: cereal could not find any output serialization functions for the provided type and archive combination.

 Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these).
 Serialize functions generally have the following signature:

 template<class Archive>
   void serialize(Archive & ar)
   {
     ar( member1, member2, member3 );
   }
4

0 回答 0