Cereals do not support raw pointers

Edit: The title of the question was based on a deep misunderstanding of the compiler error I received. I was (stupid), assuming the error was that I tried to deserialize the object declared inside the function. This was completely wrong. I did not make enough effort to debug myself, or I could find out what happened. So the title was a pretty miss, and I changed it. Thanks Andrey Benkovsky for the help.


I write serialization functions for 3D models in my engine using cereals, which is really effective and easy to use. So far, everything worked perfectly when I tested (dea) serializing a simple Mesh. But now I am trying to deserialize another class, but have run into a problem that I am not getting.

void loadFile(std::string filepath)
{
    DescriptionFile file;

    {
        ifstream stream = ifstream(filepath, std::ifstream::binary);
        PortableBinaryInputArchive archive(stream);
        archive(file);
        stream.close();
    }
}

This is my class that should be deserialized:

struct DescriptionFile 
{
public:
    DescriptionFile(){}

    map<string, MeshDescription*> meshDescriptions;
    map<string, ModelDescription*> modelDescriptions;

public:
    template<class Archive>
    void serialize(Archive & archive)
    {
        archive(meshDescriptions, modelDescriptions);
    }
};

This gives me a compiler error: Cereal does not support serializing source pointers - use a smart pointer Although this is not a pointer. In another part of the code, something like this works fine. I would be glad if anyone could help me with this.

+4
source share
1 answer

Cereal, , - :

map<string, unique_ptr<MeshDescription> >

std:: unique_ptr #include <memory>

:

, ( , , int *) . , <cereal/types/memory.hpp>.

, , .

P.S. (, MeshDescription), (, , ..) ( , , ..). . 0.

+2

Source: https://habr.com/ru/post/1613186/


All Articles