Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Serializing derived template classvia base pointer
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-01-17 15:01:24


Daniel Mitchell wrote:
> Hi everyone, has any progress has been made on a general solution for
> this problem? Given classes like these,
>
> struct base {
> template<typename Archive>
> void serialize(Archive& ar, unsigned version) { }
> virtual ~base() = default;
> };
>
> template<typename T>
> struct derived : base {
> template<typename Archive>
> void serialize(Archive& ar, unsigned version) { ar & data; }
> T data;
> };
>
> is it possible to serialize the derived type (with T unknown) via a
> base pointer? Sticking a call to register_type<derived> in
> derived::serialize doesn't seem to do it.

There are several demos in the examples directory which show how to do this.

Robert Ramey


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