Boost logo

Boost Users :

Subject: Re: [Boost-users] Serialize abstract base class
From: Fabian Weiss (fabian.weiss_at_[hidden])
Date: 2011-11-03 03:16:16


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:

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