|
Boost Users : |
Subject: Re: [Boost-users] [Serialization] How to serialize a derived type but deserialize it as a base type pointer?
From: Jerry (jerryunsw_at_[hidden])
Date: 2011-04-12 01:06:01
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] <
ml-node+3443692-1803786549-229290_at_[hidden]> 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://user/SendEmail.jtp?type=node&node=3443692&i=0&by-user=t>
> 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
> To unsubscribe from [Serialization] How to serialize a derived type but
> deserialize it as a base type pointer?, click here<http://boost.2283326.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3440971&code=amVycnl1bnN3QGdtYWlsLmNvbXwzNDQwOTcxfC0xNjkzNTA5OTY4>.
>
>
-- View this message in context: http://boost.2283326.n4.nabble.com/Serialization-How-to-serialize-a-derived-type-but-deserialize-it-as-a-base-type-pointer-tp3440971p3443724.html Sent from the Boost - Users mailing list archive at Nabble.com.
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