From: Robert Ramey (ramey_at_[hidden])
Date: 2005-09-09 16:45:25
Loïc Joly wrote:
> Robert Ramey a écrit :
>>> Of course, if I replace B const *pc by B *pc, then the code works
>>> correctly.What can I do to serialize pointers to const data ?
>> Or you could replace this above with:
>> ar & const_cast<B *>(pc);
>> (or maybe const_cast<B * &>(pc)
> I really do not understand why I would have to do that.
>> But that would override the normal meaning of "const" as applied to
>> a member variable.
> In this case, the member variable is not const. It's not like in
> http://www.boost.org/libs/serialization/doc/serialization.html#const .
> It's just a non const pointer that refers to a non const class defined
> elsewhere, but that promise not to modify that class himself.
correct. Its a non-const pointer to a const object. But if the object is
const then it is prohibited from being modified. Serialization has no
special privleges in this regard. So loading it traps at compile time -
just as would anyother attempt to modify the object that B is pointing to.
>> You really have to ask yourself what you want serialize to
> Could you please explain this point ? I do not understand what you
If you want the object pointed to by pc to be modifiable by serializaltion
then it shouldn't be const.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk