On Jul 14, 2008, at 5:40 PM, Steve Sanders wrote:
Thank you, that makes my sample work. These points could be clearer in the docs, I would say.
From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Monday, July 14, 2008 2:54 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [serialization] Visual Studio 2008 + Boost 1.35:runtime casting not working
The base class MUST be polymorphic - that is have at least one virtual function.
AND the the pointer to the base class - not the derived class should be serialized.
How strict is the requirement that a base class has to be
polymorphically connected to the derived class? I have a class that
derives from a class template that uses the curiously-recurring
template pattern. Such base classes are usually without any kind of
virtual stuff, to allow inlining of parent methods and avoid the hit
virtual dispatch.
//==============================================
template < class Derived >
class counter_base
{
public:
void count() { ++counter; }
int current_count() const { return counter; }
protected:
counter_base() : counter( 0 ) {}
private:
int counter;
friend class boost::serialization::access;
template < class Archive >
void serialize( Archive &ar, unsigned const file_version )
{ ar & counter; }
};
class my_class
: private counter_base