Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] shared_ptr to const object
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-12-21 14:14:03

Steven Watanabe wrote:
> elizabeta petreska wrote:
>> I just want to say that I managed to solve this problem without
>> creating a temporary , thanks to this thread :
>> And here it is what I have got in my problem :
>> boost::shared_ptr<const TT> jj(new TT(5));
>> {
>> boost::archive::xml_oarchive oa(ofs);
>> }
>> boost::shared_ptr<const TT> rjj;
>> {
>> void* xptr=&rjj;
>> boost::shared_ptr<TT> *xxptr;
>> xxptr=static_cast< boost::shared_ptr<TT> * > (xptr);
>> boost::archive::xml_iarchive ia(ifs);
>> }
> This is undefined behavior. I would strongly advise against it
> if there is a reasonable alternative.
> In Christ,
> Steven Watanabe

Note that for better or worse, the serialization library does a lot of this
of thing internally. If fact, a number of key facilities (e.g. export, usage
of DLLS, etc depend
on behavior which is technically undefined, but necessary to implement them.
getting them to work at all was a huge challenge. I doubt that the above
is any more risky than many usages of the library itself.

Robert Ramey

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at