serialization basic question

Hi, I'm trying to use the serialization library and was having a compile error using MSVC 2005. So I decided to try and compile "A Very Simple Case" from the tutorial, and that of course works. But then I noticed that the example serializes a const object, that sort of is rather useless, so I removed the const specifier, and I got the same error that I was getting with my program, namely: warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class' I went googling for an answer and I found that I should look at the rationale on the docs, but the rationale (http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/rationale.html) doesn't seem at all relevant. I finally sort of guessed that I wanted was probably to modify the tracking behavior on my program (looking at the thread http://lists.boost.org/boost-users/2010/05/59107.php ). But my objects are not on the stack, so I'm not really sure. My class structure is a bit more complicated than the simple example, but my question basically is, what changes would be appropriate on the simple example so that it would compile for non-const objects? Thanks

Hi Luis,
could you post a simple code to demonstrate your problem?
On Fri, Oct 14, 2011 at 02:47, Luis A. Montes
Hi, I'm trying to use the serialization library and was having a compile error using MSVC 2005. So I decided to try and compile "A Very Simple Case" from the tutorial, and that of course works. But then I noticed that the example serializes a const object, that sort of is rather useless, so I removed the const specifier, and I got the same error that I was getting with my program, namely: warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class'
I went googling for an answer and I found that I should look at the rationale on the docs, but the rationale ( http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/rationale.html ) doesn't seem at all relevant. I finally sort of guessed that I wanted was probably to modify the tracking behavior on my program (looking at the thread http://lists.boost.org/boost-users/2010/05/59107.php ). But my objects are not on the stack, so I'm not really sure. My class structure is a bit more complicated than the simple example, but my question basically is, what changes would be appropriate on the simple example so that it would compile for non-const objects?
Thanks
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Fri, 2011-10-14 at 07:20 +0800, Hazrat Pradipta Ranjali wrote:
Hi Luis,
could you post a simple code to demonstrate your problem?
Yes, Actually the posted code on the tutorial does: http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/tutorial.html#si... my question is why does it have to be a const object on line 51. If you take the const specifier the compilation fails (and on my program I can't make them const). I found that if you add: BOOST_CLASS_TRACKING(gps_position, boost::serialization::track_never) then the compilation succeeds, but that sort of begs the question, why the default behavior is not the most convenient one in this simple case? (Paraphrasing "Object Tracking" on the documentation) That's what I ended up doing in my code as well, but I'm not sure that's the appropriate solution, and as I mentioned, the rationale on the documentation does not seem to speak of that. Thanks for your patience with a newbie,
On Fri, Oct 14, 2011 at 02:47, Luis A. Montes
wrote: Hi, I'm trying to use the serialization library and was having a compile error using MSVC 2005. So I decided to try and compile "A Very Simple Case" from the tutorial, and that of course works. But then I noticed that the example serializes a const object, that sort of is rather useless, so I removed the const specifier, and I got the same error that I was getting with my program, namely: warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class' I went googling for an answer and I found that I should look at the rationale on the docs, but the rationale (http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/rationale.html) doesn't seem at all relevant. I finally sort of guessed that I wanted was probably to modify the tracking behavior on my program (looking at the thread http://lists.boost.org/boost-users/2010/05/59107.php ). But my objects are not on the stack, so I'm not really sure. My class structure is a bit more complicated than the simple example, but my question basically is, what changes would be appropriate on the simple example so that it would compile for non-const objects?
Thanks
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Luis,
I recall (many years ago) that in MSVC world a struct and a class are
not equivalent. I would need to see your code to tell you more. I am
in the process of using boost serializaiton myself, but on a Linux
platform.
Jon
On Thu, Oct 13, 2011 at 11:47 AM, Luis A. Montes
Hi, I'm trying to use the serialization library and was having a compile error using MSVC 2005. So I decided to try and compile "A Very Simple Case" from the tutorial, and that of course works. But then I noticed that the example serializes a const object, that sort of is rather useless, so I removed the const specifier, and I got the same error that I was getting with my program, namely: warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class'
I went googling for an answer and I found that I should look at the rationale on the docs, but the rationale (http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/rationale.html) doesn't seem at all relevant. I finally sort of guessed that I wanted was probably to modify the tracking behavior on my program (looking at the thread http://lists.boost.org/boost-users/2010/05/59107.php ). But my objects are not on the stack, so I'm not really sure. My class structure is a bit more complicated than the simple example, but my question basically is, what changes would be appropriate on the simple example so that it would compile for non-const objects?
Thanks
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Luis A. Montes wrote:
Hi, I'm trying to use the serialization library and was having a compile error using MSVC 2005. So I decided to try and compile "A Very Simple Case" from the tutorial, and that of course works. But then I noticed that the example serializes a const object, that sort of is rather useless, so I removed the const specifier, and I got the same error that I was getting with my program, namely: warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class'
I went googling for an answer and I found that I should look at the rationale on the docs, but the rationale (http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/rationale.html) doesn't seem at all relevant.
This is the best explanation I can give to address the issue with "const". Even if you don't buy the explanation, it's easy to avoid by using a const_cast. Robert Ramey

On Thu, 2011-10-13 at 21:59 -0800, Robert Ramey wrote:
Luis A. Montes wrote:
Hi, I'm trying to use the serialization library and was having a compile error using MSVC 2005. So I decided to try and compile "A Very Simple Case" from the tutorial, and that of course works. But then I noticed that the example serializes a const object, that sort of is rather useless, so I removed the const specifier, and I got the same error that I was getting with my program, namely: warning C4099: 'boost::serialization::static_warning_impl<false>::STATIC_WARNING' : type name first seen using 'struct' now seen using 'class'
I went googling for an answer and I found that I should look at the rationale on the docs, but the rationale (http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/rationale.html) doesn't seem at all relevant.
This is the best explanation I can give to address the issue with "const". Even if you don't buy the explanation, it's easy to avoid by using a const_cast.
Robert Ramey
Thanks, Robert First of all I didn't mean to criticize, it's just that for me things are not as clear because I'm not an expert, so it's not like I don't buy it, I just don't see it. But I'll take your word for it. So a const cast it is. If you can indulge me a little bit more, though, what I did to fix my problem, that works on the tutorial example as well, was to add: BOOST_CLASS_TRACKING(MyClass, boost::serialization::track_never) If I understand it right, I would want object tracking only if my classes somewhere in their implementation use pointers to keep track of members. I don't do that but I do use STL containers in several places. Am I liable to break serialization by using that macro? If you think I should just RTFM, please do so (I think I did, though) Thanks again for a very useful library
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Luis A. Montes wrote:
If I understand it right, I would want object tracking only if my classes somewhere in their implementation use pointers to keep track of members.
it could be that you're serializing classes which contain a reference so you would want to track even if you're not explicitly using pointers. So I would advice against this solution. There a a very long section in the manual explaining why I chose to require that values being saved be const. I seem to remember that I changed the error into a warning but I might be wrong about this. From my perspective if a C++ programmer has made a sincere effort to understand the manual and hasn't been successful, it's a bug in the manual. So if you want to post a minimal example (maybe you already did and I forgot) I'll have a look at it. Robert Ramey
participants (4)
-
Hazrat Pradipta Ranjali
-
Jonathan Bishop
-
Luis A. Montes
-
Robert Ramey