Re: How to serialize reference members using boost::serialization
Thanks, Alf, for your response.
On 2 Mar, 15:16, "Alf P. Steinbach" <a...@start.no> wrote:
* Abhishek Padmanabh:
Thank you for your replies.
Here is an example that I had prepared for working with references
(and you can see how const is handled without const_cast<>) -
http://www.codeguru.com/forum/showthread.php?t=415510
Your code (it would be better to just include it, because it's short):
Sorry that I did not specify the link to the exact post I was
referring to. You picked up the older version of my code. If you
scrolled down to the last post there, that's my latest code. Here is
the relevant link to it -
http://www.codeguru.com/forum/showpost.php?p=1537732&postcount=4
I have corrected quite a few things there.
Sort of. reinterpret_cast introduces undefined behavior. For
example, it may be that the Boost serialization framework is calling
the 'serialize' member on that uninitialized object. Also, when
using '::new' you really should include the <new> header. Presumably
it's included by chance by one of the other headers.
The latest version does not include reinterpret_cast<>. Thanks for
pointing about the <new> header inclusion.
Second, the in-place construction won't work well in a hierarchy of
classes, so it's not a general technique.
Can you please expand on this? I suppose if boost suggest in-place
construction, they must be handling deserialization well. Since, I
don't know the internals, I too think it might get complicated when
the class is an intermediate one in a hierarchy. Not perfectly sure,
though.
You're not handling the reference member correctly because in the
original object it's bound to a global. The serialization framework
doesn't know anything about your globals. The only default a
serialization framework can apply is to assume that a pointer points
to a dynamically allocated object (I don't know if Boost does that),
and otherwise you'll have to handle it yourself.
If binding to the global is incorrect, how should I handle such cases?
How shall things change if the reference member is bound to a member
of another independent object serialized similarly?
That's what you're doing. It's evidently not correct in the sense of
"reproducing" the original object with a reference to a global. But
whether the code is correct with respect to Boost serialization
requirements, I can't say, because I don't know those requirements.
I was testing the functionality in a general sense. My requirement is
as simple as "how to serialize and deserialize any object that has a
reference member?". What the reference is bound to, is not that
important for now.
Please, if you (or anyone else) can comment on my latest code and let
me know the things I am doing wrong? I don't have a good feeling about
it, that's why I ask. Thank you very much for all the response until
now.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]