|
Boost Users : |
Subject: Re: [Boost-users] [Serialization] Runtime error in load_pointer
From: elizabeta petreska (elizabeta.petreska_at_[hidden])
Date: 2010-01-19 15:07:21
I am sorry for the trouble, I write wrong, I meant vector<const T*>
The asymetry came because I was doing the following :
class X {
vector<const T*> m_v;
template<class Archive>
void save(Archive & ar, const unsigned int version) const {
ar & m_v;
}
template<class Archive>
void load(Archive & ar, const unsigned int version){
void* ptr=&m_v;
vector<T*> *mptr;
mptr=static_cast<vector<T*>*>(ptr);
ar & (*mptr);
}
...
};
On Tue, Jan 19, 2010 at 6:54 PM, Robert Ramey <ramey_at_[hidden]> wrote:
> elizabeta petreska wrote:
> > Again thank you all who helped me in this .
> >
> >>> This is likely a secondary effect from some other error.
> > It was secondary error.
> >
> >>> A complete shot in the dark but it is possible it might be the
> >>> problem.
> >
> > This was the problem, so it wasn't shot in the dark at all.
> > The problem was that my classes have the following class members :
> > shared_ptr<const T> , vector<const T>, vector<shared_ptr<const T>>
> > and many others that have const inside them. I can not remove const
> > from these, altghough I wish :)
> > I was casting const away (http://tinyurl.com/yae5stv ) for all this
> > members only at the point of loading, for example in many cases I was
> > saving vector<const T> and loading vector<T>. Now I added const cast
> > at the point of saving too, so saving and loading is symmetric. It
> > seems it works Ok now, and I hope this is the right way to solve the
> > problem.
>
> I'm curious about this.
>
> a) I can't understand why vector<const T> is even valid. My understanding
> is that the value of type of a container must be Assignable and that
> a const T is by definition not assignable. So I would expect this to
> show up as an issue long before serialization is involved.
>
> b) I can't see how one gets the asymetry in the first place. E.G.
>
> class X {
> vector<const T> m_v;
> template<class Archive>
> void save(Archive & ar, const unsigned int version) const {
> ar << m_v;
> }
> template<class Archive>
> void load(Archive & ar, const unsigned int version){
> ar >> m_v;
> }
> ...
> };
>
> Hmmm I suppose that one might use a cast on a load but not on the save.
> This is a case which in fact I've never considered. I'll think about this.
>
> Meanwhile, any C++ STL gurus can feel free to comment on a) above.
>
> Robert Ramey
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net