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<>a2;
ia>>c2;
}
catch(boost::archive::archive_exception& ae)
{
cout<
Hi, Why do you think that this should work? I would assume that serialisation dos only make sense if serialization and reconstruction are symmetric. This cas does not look very symmetric to me. On 2012-10-23 19:31, Larry E. Ramey wrote:
Is this by design? Seriously? I can't save derived pointers and unarchive base pointers?
Larry
Larry E. Ramey wrote:
Is this by design?
yes
Seriously?
yes
I can't save derived pointers and unarchive base pointers?
no the extra information indicating what kind of pointer is is only saved when necessary. That is when the saving is done through a base class pointer. In general all saving/loading must be between the same types. Seriously. Robert Ramey
Larry
I split my test program up from 1 .cpp file into proper headers and implementation files.... (we'll fight the fight with dlls next)
I now get a unregisted_class exception when I do this: (MSVC 11.0, windows7, win32 compile)
int main(int argc, char* argv[])
{
const ABase* a = new ABase("I'm cool");
const ABase* c = new C(*a,54.2f);
cout <<*a<<"\n"<<*((C*)c)<
participants (3)
-
Larry E. Ramey
-
Oswin Krause
-
Robert Ramey