I've the following problem..
I have a file called A.h and a file B.h. each contains some struct like this: (the structs inside the two classes are different)
struct Base
{
friend class access;
template <typename Archive>
void serialize(Archive& ar,const unsigned int version)
{
ar & fieldLength;
ar & fieldMD;
ar & fieldTime_Stamp;
}
public:
unsigned int fieldLength;
unsigned int fieldMD;
unsigned int fieldTime_Stamp;
virtual void f(){} //to be polymorphic the struct
};
struct Derived:public Base
{
...
}
So i serialize the struct in the classic manner:
....
std::ostringstream archive_stream;
boost::archive::text_oarchive archive(archive_stream);
archive.register_type(static_cast<Derived*>(NULL))
archive <<p; // where p is a pointer to Base
NOW THE PROBLEM... on the deserialization side, I follow the same (inverse) procedure...if I deserialize singularly the structs in A.h (without include in the project B.h) and the structs in B.h (without include in the project A.h) all works....but If I include in the project both the classes, the deserialization works for one class, but throws the "Stream error exception" in the instruction " archive >> m;" for the other...it seems a conflict in the registration class or something like this... Any ideas?tha开发者_开发技巧nks...
Have you serialised the base data in the derived class serialize function?
ar & boost::serialization::make_nvp( "base", boost::serialization::base_object< Base >( *this ) );
And I dont know if this would help, but I use
BOOST_CLASS_IMPLEMENTATION(x, boost::serialization::object_serializable);
BOOST_CLASS_TRACKING(x, boost::serialization::track_never)
to register the classes as serialiseable. Hope that helps :3
精彩评论