Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2002-11-17 13:19:01


Date: Sun, 17 Nov 2002 12:49 +0000 (GMT)
From: brangdon_at_[hidden] (Dave Harris)
>> "Serialization Overrides" explains this and gives a code excerpt
>> showing what one has to do to use a constructor with arguments.

>The code looks roughly like:

> ar >> a;
> t = new T(a);
> ar >> *t;

>Is it possible to support code like:

> t = new T(ar);

>Or indeed:

> const T t(ar);

>? It seems to me that your versioning infrastructure doesn't support this.

It doesn't . It conflicted with version and added no known benefit.

>At first sight this seems like a problem.

what problem?

> class MyClass {
> const MyMember m_member1;
> const MyMember m_member2;
> public:
> MyClass( boost::basic_iarchive &ar ) :
> m_member1(ar), m_member2(ar) {
> }
> };

>and something like this is surely the only way to support const members.

That's not true

const members are initialized in the constructor, usually from constructor
argments. as these arguments are taken from the stream before
the object is constructed, that are passed to the constructor
and every thing works as normal. Your method would require that
every class that uses serialization and but no default constructor
have code in it that knows about archives. Non intrusive serialization
could be be implemented in this case.

>Is it your belief that this kind of thing is best discouraged? If so,

yes

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk