On Mon, 11 Apr 2011 22:06:01 -0700 (PDT), Jerry <jerryunsw@gmail.com> wrote:
Thanks Robert. You mis-understood my intention. What we want is to serilaize an derived type object directly (not throught base type pointer) but deserialize it to a base type pointer. So we want the exactly the following codes:
 
Derived d;
oa << d;
 
Base* b;
ia >> b;
 
But it seems this does not work. The reason we prefer this is that we have three nodes. One node sends/serialize the derived type object, while two other nodes are receivers. Howerver, one receives/deserializes the obj via derived type and the other deserializes the obj via base type pointer. We want,
 
// The sender
Derived d;
oa << d;
 
// One Receiver 
Base* b;
ia >> b;
 
// The other Receiver 
Derived dcopy;
ia >> dcopy;
 
 
 
On Tue, Apr 12, 2011 at 2:14 PM, Robert Ramey [via Boost] <[hidden email]> wrote:
Jerry wrote:
> I know that we can serialize/deserialize a derived type through a
> base type pointer (using register_type()). But I cannot serialize a
> derived type and deserialize it through a base type pointer. It seems
> to me the data type in serialization and deserialization should be
> extactly the same one.

when you serialize through a derived type, extra information
about the derived type isn't saved as it's assumed it will
be deserialized the same way.


>
> What I want is,
>
> Base{...};
> Derived : Base{...};
>
> //Derived d;
Base *d = new Derived; // use this instead !!

> boost::archive::binary_oarchive oa(...);
> oa << d;   // serialize a derived object
>
> Base *b;
> boost::archive::binary_iarchive ia(...);
> ia.register_type();
> ia >> b  // Deseiralize to a base type pointer
>
> I have tried this but it does not work. Is there any way to make this
> work?
>
> Many thanks!!!



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users



If you reply to this email, your message will be added to the discussion below:
http://boost.2283326.n4.nabble.com/Serialization-How-to-serialize-a-derived-type-but-deserialize-it-as-a-base-type-pointer-tp3440971p3443692.html



View this message in context: Re: [Serialization] How to serialize a derived type but deserialize it as a base type pointer?
Sent from the Boost - Users mailing list archive at Nabble.com.