Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-02-15 13:28:51


This is not hard - but it can be tricky. To use many of the features of the
serialization library you can almost just slap it together, fix up the
errors and be amazed that it works. Not true with serialization through a
base class pointer.

a) read the documenation and examples on this point.
b) if you want to do this with smart pointers, look at the smart pointer
demo/example
c) remember to make your base class polymorphic - make at least one function
virtual.

Serialization through a base class pointer can be very useful and powerful
techniqued.

Good Luck

Robert Ramey

Aljaz wrote:
> Hello..
> I use serialization to communicate betwen client and server..
>
> Base and derived class for serialization (communication):
>
> class base {
> };
> class derived : base {
> };
>
> What would be the 'good' way to export/import serialized data?
> Can I do this with smart pointers?
>
>
> Is this okay:
>
> WRITING:
> derived dc(4, 5, "some data");
> std::ostringstream archive_stream;
> boost::archive::text_oarchive archive(archive_stream);
> archive & dc;
> //send archive_stream.str() over network
>
>
> RECIVING:
> should I use base class pointer when deserializing?
> or can I do it with base class reference?
>
> For instance:
> base *bc;
> bc & in_data;
>
> /////////
> I'm little confused about reciving data.. I tried using base class
> reference for deserializing derived class, but it doesnt work and it
> seems unlogical to do it this way..
> I would be really glad if someone could explain..
>
> Thanks a lot


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