2

我想试一试谷物序列化库。我是初学者级别的 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,
            ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4

0 回答 0