Boost logo

Boost Users :

From: Jason Gorski (gorski_at_[hidden])
Date: 2007-08-16 14:36:12


Robert Ramey wrote:
> I believe this is a manifestation of a header order dependency which is
> fixed in a more recent version.
>
> Robert Ramey
>
> Jason Gorski wrote:
>
>> Hello,
>>
>> I have been using the Boost Serialization libraries on a project of
>> mine and so far they have worked very well. However, I have been
>> unable to properly load derived objects using a base class pointer.
>> The following code generates an unregistered class exception:
>>
>> #include <iostream>
>> #include <sstream>
>> #include <iomanip>
>> #include <string>
>> #include <sstream>
>>
>
>
>> #include <boost/serialization/export.hpp> // try putting serialization
>> headers before archive headers
>>
>
>
>> #include <boost/archive/text_oarchive.hpp>
>> #include <boost/archive/text_iarchive.hpp>
>>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> .
>
>
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 <boost/serialization/serialization.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

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


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