Boost logo

Boost Users :

Subject: [Boost-users] serialization
From: Larry E. Ramey (hydrajak_at_[hidden])
Date: 2012-10-23 13:31:17


I've got a system where class A {   A();   A(const string&);   virtual ~A(); }; class C : public A {     C();     C(const A&, float);     virtual ~C(); }; BOOST_CLASS_EXPORT( A ) BOOST_CLASS_EXPORT( C ) main() { ... const A* a = new a("stuff"); const C* c = new c(*a, 52.54390f); {     ofstream ofs("dump.bin");     boost::archive::text_oarchive oa(ofs);     oa<<a<<c; } ... A* a2=NULL; C* c2=NULL; try {         ifstream ifs("dump.bin");         boost::archive::text_iarchive ia(ifs);         ia>>a2;         ia>>c2; } catch(boost::archive::archive_exception& ae) {         cout<<ae.what(); } } This works just fine. If I replace A* a2=NULL; C* c2=NULL; with A* a2=NULL; A* c2=NULL; Then it throws an unregistered_class exception. If I change the iarchive to take: const A* a = new A("I'm cool"); const A* c = new C(*a,54.2f); then I can unarchive it with a pair of A*. Is this by design? Seriously? I can't save derived pointers and unarchive base pointers? Larry



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