From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-01-22 02:09:56
Robert Ramey wrote:
>>My understanding was that as you declare derived class, you also invoke
>>BOOST_CLASS_EXPORT on it, and now you can save pointers to that class
>>But this does not work in my tests. Unless I use BOOST_CLASS_EXPORT in the
>>code which does actual saving, I get:
>>static void boost::serialization::detail::save_pointer_type<Archive,
>>TPtr>::polymorphic<T>::save(Archive&, const T&, const
>>boost::serialization::basic_oserializer*) [with T = B, Archive =
>>boost::archive::text_oarchive, TPtr = B*]: Assertion `__null != vp'
>>Test case attached. Am I doing something wrong?
> This is explained in the header code at basic_archive.hpp:125
> Remember your problem with PIMPL ? well it shows up again with export in
> a particularly
> subtle way.
Yea, I wondered how BOOST_CLASS_EXPORT would instantinate necessary
'serialize' but since docs say it will, I though it would magically
work in all cases ;-)
> Suppose I export a derived pointer but otherwise never
> explicitly refer to
> it a compile time. Code with template parameters <Archive, T> will never
> get instantiated. So EXPORT has two functions
> a) make sure that a class is registered in a archive by its key string
> b) instantiate required code to serialize the given type with all the
> archives used by the program.
> In order to do this, EXPORT builds an mpl::list of all the file types
> used by the module by
> check for definition of the head inclusion guards. Using mpl, the proper
> serialization code is explicitly instantiated so that it can be invoked if
Now I see there's boost::archive::known_archive_types.
> In order for this work, export.hpp has to come after the archive header
> .hpp files. This is enforced by the code that tripped above.
> I spent lots of time finding a solution to this difficult problem and am
> pleased with the result.
IOW, it's required that archives to be used with exported classes
are included before you do BOOST_EXPORT? Indeed, when I add
everything starts to work. I guess I've no problem with this solution --
since I don't know how else EXPORT would work.
But it's unfortunate to get assert like above -- newbie will immediately
decide it's a bug in serialization library. OTOH, requiring that all archive
headers are included before BOOST_CLASS_EXPORT is probably overkill.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk