jeudi 26 octobre 2017

Can't serialize std::vector with Cereal

I'm new to serialization, and I'm having trouble serializing std::vector objects with the Cereal library. Here's a sample that illustrates the problem:

class MyClass
{
    int x, y, z;

    class MyOtherClass
    {
        string name, description;

    public:

        template<class Archive>
        void serialize(Archive & archive)
        {
            archive(name, description);
        }
    };

    vector<MyOtherClass> Victor;
    vector<int> ints;

public: 

    template<class Archive>
    void serialize(Archive & archive)
    {
        archive(x, y, z, ints); // error C2338: cereal could not find any output serialization functions for the provided type and archive combination.
    }
};

Attempting to serialize either the ints object or the Victor object results in error C2338: cereal could not find any output serialization functions for the provided type and archive combination.

Here's the code I use in the main function:

MyClass MyObject;
ofstream datafile(path, ios::binary);
{ cereal::BinaryOutputArchive oarchive(datafile); oarchive(MyObject); }

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire