|
Boost : |
From: Loïc Joly (loic.actarus.joly_at_[hidden])
Date: 2005-09-12 15:28:33
Robert Ramey a écrit :
>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 ?
>>>>
>>>>Regards,
>>>>
>>>>
>>>>
>>>>
>>>Or you could replace this above with:
>>> ar & const_cast<B *>(pc);
>>>(or maybe const_cast<B * &>(pc)
>>>
>>>
>>>
>>>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.
>
My only issue is that the other objetc is not const, and in fact, it has
already been saved before. It is just const seen from A point of view.
But I understand that is would be quite difficult to differenciate such
a case from a case where the only access to the B object is through A.
I think I will use this const_cast. This is I think the first time I
find any use for a const_cast.
Thank you for your help,
-- Loïc
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk