Boost logo

Boost Users :

From: Jarl Lindrud (jlindrud_at_[hidden])
Date: 2005-01-11 11:05:07

Hi! A question on serializing pointers to derived classes:

When I serialize naked polymorphic pointers through base pointers, things
work as expected, ie the derived classes are serailized and deserialized.
However, when I replace the naked pointers with corresponding
boost::shared_ptr's, I get an archive_exception, to the tune of
"unregistered class".

I'm using BOOST_CLASS_EXPORT, and not the register_type<> functions.

Is this supposed to happen, or do I need some additional type registration
beyond what was necessary for serializing naked pointers?



The code:

//B and C derive from A

std::ostringstream os;
boost::archive::text_oarchive oa(os);
//A *pb0 = new B(15,16);
//A *pc0 = new C(17, 18, 19);
boost::shared_ptr<A> pb0( new B(15,16) );
boost::shared_ptr<A> pc0( new C(17, 18, 19) );
oa << pb0;
oa << pc0;
std::string data = os.str();

    std::istringstream is(data);
    boost::archive::text_iarchive ia(is);
    //A *pa1 = NULL;
    //A *pa2 = NULL;
    boost::shared_ptr<A> pa1;
    boost::shared_ptr<A> pa2;
    ia >> pa1;
    ia >> pa2;
    B* pb = dynamic_cast<B *>(pa1.get());
    C* pc = dynamic_cast<C *>(pa2.get());

Express yourself instantly with MSN Messenger! Download today it's FREE!

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at