1

I ran into a problem when serialising shared pointers with Cereal. I have the following class struture:

class Source
{
    std::string name;

    template<class Archive> void serialize(Archive & archive)
    {
        archive(name);
        std::cout << "SN: " << "(" << m_Name << ")";
    }
};

class Event
{
    std::shared_ptr<Source> source;

    const std::shared_ptr<Source>& getSource() const 
    {
       return source;
    }

    template<class Archive> void serialize(Archive & archive)
    {
        archive(source);
        std::clog << "EN: " << "(" << getSource()->getName() << ")" << "ENP: " << source.get() << std::endl;
}

};

By running my main code I have the following output:

SN: (l_32)EN: (l_32)ENP: 0x7f9f90001450

SN: (l_13)EN: (l_13)ENP: 0x7f9f90001b80

SN: (l_4) EN: (l_4) ENP: 0x7f9f90002100

SN: (l_58)EN: (l_58)ENP: 0x7f9f90002280

SN: (l_27)EN: (l_27)ENP: 0x7f9f90002340

SN: (l_81)EN: (l_81)ENP: 0x7f9f900028b0

SN: (l_65)EN: (l_65)ENP: 0x7f9f90002970

SN: (l_49)EN: (l_49)ENP: 0x7f9f90003140

SN: (l_73)EN: (l_73)ENP: 0x7f9f90003200

SN: (l_99)EN: (l_99)ENP: 0x7f9f900032c0

SN: (l_33)EN: (l_33)ENP: 0x7f9f90003380

SN: (l_14)EN: (l_14)ENP: 0x7f9f90002af0

EN: (l_5) ENP: 0x7f9f90001510

It looks like that for the Event (l_5), it does not serializes the shared pointer. According to the documentation of Cereal, this happens if the shared pointer is already serialized. By printing out the addresses as well I can conclude that this is not the case.

Could you please advise?

Minee
  • 408
  • 5
  • 12

0 Answers0