Boost logo

Boost Users :

From: Chris Coleman (cqc_at_[hidden])
Date: 2005-07-19 14:29:40


Ok,

I've since found some information on Object Tracking in another boost
list that I missed previously. (apologies) This suggests the behaviour
is now correct, and that 1.32 implementation was overly relaxed.

As I understand it the << operator require a const reference to the
object to be serialized inorder to prevent the same object being written
or read, to or from an archive multiple times. So you can now no longer
serialize a pointer to an object, even if its a const ptr?

My solution has been to dereference the object as below, and it compiles
and seems to work. However, I'm not convinced this is the correct way
of doing things.

oa << *memory->pull_slice(slice_id);
ofs.close();

where pull_slice returns a const * to the object to be serialized. Is this best?

Also, it's not really my place to say, but as a user it would probably be really useful if these changes were emphasised in the release notes or somewhere appropriate / obvious to avoid too people spamming the list with unnecessary questions as I have just done... <slopes of feeling stupid>

Cheers
Chris

Chris Coleman wrote:

>Hi,
>
>I'm having trouble with serializing an object through a pointer to it.
>
>The code below works in 1.32, but in 1.33 it gives the errors below. I
>am using Mac OS X 10.4.2, gcc 4.0.
>
>I've had a look at the headers, but my template programming isn't good
>enough to make too much sense of them. It seems that there is a check
>to ensure T is not a pointer on line 549 of oserializer.hpp, which is
>the reason the static assert is failing?
>
>Is it correct that objects shouldn't be serializable by pointers to
>them, or not?
>
>Cheers
>Chris
>
>
>gps_position* p_g = new gps_position(35, 59, 24.567f);
>oa << p_g; // causes the error's below
>
>
>g++ -o test test.cpp -lboost_serialization-d-1_33
>/usr/local/include/boost/archive/detail/oserializer.hpp: In function
>'void boost::archive::save(Archive&, T&) [with Archive =
>boost::archive::text_oarchive, T = gps_position*]':
>/usr/local/include/boost/archive/basic_text_oarchive.hpp:78:
>instantiated from 'void
>boost::archive::basic_text_oarchive<Archive>::save_override(T&, int)
>[with T = gps_position*, Archive = boost::archive::text_oarchive]'
>/usr/local/include/boost/archive/detail/interface_oarchive.hpp:85:
>instantiated from 'Archive&
>boost::archive::detail::interface_oarchive<Archive>::operator<<(T&)
>[with T = gps_position*, Archive = boost::archive::text_oarchive]'
>hash_test.cpp:130: instantiated from here
>/usr/local/include/boost/archive/detail/oserializer.hpp:560: error:
>invalid application of 'sizeof' to incomplete type
>'boost::STATIC_ASSERTION_FAILURE<false>'
>
>
>
>This message has been checked for viruses but the contents of an attachment
>may still contain software viruses, which could damage your computer system:
>you are advised to perform your own checks. Email communications with the
>University of Nottingham may be monitored as permitted by UK legislation.
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.


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