
In this case your commiting an error. You're saving an object and loading a pointer. You have to save and load to the same thing. Robert Ramey
Thanks for the quick response! However, I have just started noticing a more pressing issue with the library. When I load a previously serialized object, the values seem to load out of order. For example, in the following code:
#include <iostream> #include <sstream> #include <iomanip> #include <string> #include <sstream> #include
#include #include class Some_Class { public:
int i1; int i2; int i3;
friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & i1; ar & i2; ar & i3; }
};
/***************************************** Main *****************************************/ int main() {
Some_Class send; send.i1=11; send.i2=12; send.i3=13;
Some_Class * recv;
// save class std::ostringstream output_stream; boost::archive::text_oarchive output_archive( output_stream ); output_archive & send;
// prints out: 22 serialization::archive 4 0 0 11 12 13 std::cout << output_stream.str() << std::endl;
// load class ptr std::istringstream input_stream( output_stream.str() ); boost::archive::text_iarchive input_archive( input_stream );
input_archive & recv;
std::cout << recv->i1 << std::endl; // prints out: 12 std::cout << recv->i2 << std::endl; // prints out: 13 std::cout << recv->i3 << std::endl; // prints out: 0
}
The class object /send/ is saved with i1=11, i2=12, and i3=13. However, when I load the class pointer /recv/ with the serialized data, /i1/=12, /i2/=13 and /i3/=0. How is this possible? I am using boost version 1.34.1.
Thanks! Jason