Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] How to serialize a derived type but deserialize it as a base type pointer?
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2011-04-12 07:53:01


Jerry 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:

I think Robert understands. The serialization library relies on the
types saved to an archive be equal to the types being loaded from that
archive.

> Derived d;
> oa << d;

Requires:

Derived d;
ia >> d;

If you do:

Derived* d; // note pointer
oa << (Base*)d

The you can:

> Base* b;
> ia >> b;

HTH, Jeff


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