谷物std ::矢量序列化

时间:2018-02-12 16:29:15

标签: c++ c++11 serialization stdvector cereal

我想尝试一下谷类序列化库。我在初学者级别的c ++和java的退休级别:)

我尝试用它来序列化载体但不能。

有什么建议吗? 我有以下代码并给出错误。我在这里缺少什么?

struct personv1 {
    matrix<float, 0, 1 > _descriptor;
    string person_name;
    string notes;
    matrix<rgb_pixel> s_chips;
    template<class Archive>
    void serialize(Archive & archive)
    {
        // serialize things by passing them to the archive
        archive( _descriptor, person_name,notes , s_chips );
    }
};

std::vector<personv1> person;

std::stringstream ss;

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

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

{
    cereal::BinaryInputArchive iarchive(ss); // Create an input archive
    iarchive(person); // Read the data from the archive
}

但它给出了错误:

    ---GUI-master-MAC/cereal/cereal.hpp:462: error: static_assert 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 ); 
       } 

static_assert(traits::detail::count_output_serializers<T, ArchiveType>::value != 0,
            ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 个答案:

没有答案