
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(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"
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