Boost logo

Boost Users :

Subject: Re: [Boost-users] Serialize abstract base class
From: Robert Ramey (ramey_at_[hidden])
Date: 2011-11-04 01:07:06


Fabian Weiss wrote:
> If I do not register base classe <Modul>, nor in serializing code nor
> in deserializing code:
> It compliles and serializing runs and creates perfect archive.
> But when I try to deserialize the archive I get a runtime error:

Note that the serialization and de-serialization code should be identical.
That is,

a) if you register on saving you have to do so on loading.
b) if you save as a pointer to Module, you have to load as a pointer to
Module
c) if you save as a pointer to DerivedModule, you have to load as a pointer
to DerivedModule.
... etc...

Double check this.

> terminate called after throwing an instance of
> 'boost::archive::archive_exception'
> what(): stream error
>
> How do I de/serialize: I created a class and use a vector of base
> class pointers:
>
> class LogElement
> {
> public:
> LogElement();
> virtual ~LogElement(){};
>
> std::vector<Modul*> Module;
>
> private:
> friend class boost::serialization::access;
>
> template <typename Archive>
> void serialize(Archive &ar, const unsigned int version)
> {
> ar & boost::serialization::make_nvp("Module", Module);
> };
> };
>
> In Module are pointers to objects of derived classes. Is it a problem?
>
>
> Am 03.11.2011 06:09, schrieb Robert Ramey:
>> Fabian Weiss wrote:
>>> How can I serialize my abstract base class?
>>
>> you should only need to register the derived classes.
>>
>> Robert Ramey
>>
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net