Boost logo

Boost Users :

Subject: [Boost-users] [serialization] pointer to non-constructable object
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2011-05-03 16:49:40


The problem boils down to something similar to:

struct base
{
   virtual ~base() {}
   base(x_type & obj);
};

struct derived
{
   derived() : base(member_x) {}
private:
   x_type member_x;
};

...serialize(...,base &,....) {}
...serialize(..., derived & d, ....)
{
   ar & base_object<base>(d);
   ar & member_x;
}

boost::shared_ptr<base> ptr(new derived);
ar & ptr;

The problem is that base can't be constructed without the reference. It
also makes no sense to override the construction stuff because it's
simply not how to get that reference. There's no way to construct a
base that is sensible outside of during the construction of its derived
(it's a funky design I admit, but necessary).

Unfortunately the serialization library insists on being able to
construct a base, even though I never save one except via derived
objects through a pointer to base.

I noticed a check for "is_abstract" when debugging a different issue I
had (that was totally my fault). So I tried adding a bogus virtual
function to the interface and overriding it in derived. This fixes the
problem. There must be a way to do so without such trickery though?
Can this abstract check be overridden by me?


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