Boost logo

Boost Users :

From: Aljaz (aljaz.fajmut_at_[hidden])
Date: 2007-02-15 17:08:11


Hey

I took a look at smart pointer example..
However, I need different approach in the following code:

spa = boost::shared_ptr<A>(new B);
spa1 = spa;
display(spa, spa1);
// serialize it
{
    std::ofstream ofs(filename.c_str());
    boost::archive::text_oarchive oa(ofs);
    oa.register_type(static_cast<B *>(NULL));
    oa << spa;
    oa << spa1;
}

Do I have to register_type this way? Can I use BOOST_EXPORT .. instead?
When I want to deserialize data, the derived class will be unknown, so I
have to deserialize data with base class shared pointer..
This will then contain information - type of derived class, and then I will
cast it to derived class..
How could I do this?

Thank you very much

"Robert Ramey" <ramey_at_[hidden]> wrote in message
news:er28p2$p8n$1_at_sea.gmane.org...
> 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


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