Simple serialization of int*
Hi all, I am looking for a solution to do this: int p1 = 5; int* test; test = &p1; std::ofstream out("test.bin"); boost::archive::binary_oarchive ar(out); ar << test; it does not compile. I get: Error 9 error C2228: left of '.serialize' must have class/struct/union c:\...\boost_1_37_0\boost\serialization\access.hpp I am using MSVC9. Boost 1.37.0 thanks, Sahrah -- View this message in context: http://www.nabble.com/Simple-serialization-of-int*-tp21713482p21713482.html Sent from the Boost - Users mailing list archive at Nabble.com.
I got this example while surfing :)
This example serializes float in xml, txt and binary. Serialization works perfectly but it terminates unexpectedly after doing the job.
I tested it in VS2008(VC++ 9.0). Should also work under gcc
I hope this will help you. Little modification will give your desired output.
-Rahul
To create something exceptional
________________________________
-Master4Master
"Confidentiality Warning: This message and any attachments are intended only for the use of the intended recipient(s), are confidential, and may be privileged. If you are not the intended recipient, you are hereby notified that any review, re-transmission, conversion to hard copy, copying, circulation or other use of this message and any attachments is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return email, and delete this message and any attachments from your system.
Virus Warning: Although I have taken reasonable precautions to ensure no viruses are present in this email, I cannot accept responsibility for any loss or damage arising from the use of this email or attachment."
Speak out for justice and peace,
even if your voice trembles.
________________________________
From: Sahrah
This example serializes float in xml, txt and binary. Serialization works perfectly but it terminates unexpectedly after doing the job. I tested it in VS2008(VC++ 9.0). Should also work under gcc
I've tested it with VS2008 SP1, it behaves as you've described.
I hope this will help you. Little modification will give your desired output.
?? Is this buggy? B/Rgds Max
pointers to primitive types are not serializable by default. If they were, then ALL the int values would have to be tracked - most likely not what you want. try wrapping your int in a class and serialize a pointer to that class. Robert Ramey Sahrah wrote:
Hi all,
I am looking for a solution to do this:
int p1 = 5; int* test; test = &p1; std::ofstream out("test.bin"); boost::archive::binary_oarchive ar(out); ar << test;
it does not compile.
I get:
Error 9 error C2228: left of '.serialize' must have class/struct/union c:\...\boost_1_37_0\boost\serialization\access.hpp
I am using MSVC9. Boost 1.37.0
thanks,
Sahrah
Ok, thank you. Issue solved. I don't need a work around as this was only a test. Not serializing basic type pointers is not the same as not tracking them. One could serialize them but not track them. But as this would lead to bugs I am happy the way it is. A better error message (in the way it happens when you try to serialize into xml archives without giving the entity a name) would be desirable. Maybe a comment close to this line in access.hpp? thx Sahrah Robert Ramey wrote:
pointers to primitive types are not serializable by default.
If they were, then ALL the int values would have to be tracked - most likely not what you want.
try wrapping your int in a class and serialize a pointer to that class.
Robert Ramey
Sahrah wrote:
Hi all,
I am looking for a solution to do this:
int p1 = 5; int* test; test = &p1; std::ofstream out("test.bin"); boost::archive::binary_oarchive ar(out); ar << test;
it does not compile.
I get:
Error 9 error C2228: left of '.serialize' must have class/struct/union c:\...\boost_1_37_0\boost\serialization\access.hpp
I am using MSVC9. Boost 1.37.0
thanks,
Sahrah
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- View this message in context: http://www.nabble.com/Simple-serialization-of-int*-tp21713482p21726180.html Sent from the Boost - Users mailing list archive at Nabble.com.
participants (4)
-
master master
-
Max
-
Robert Ramey
-
Sahrah