n.torrey.pines wrote:
Hi
I'm not actually worried about throwing the rest of the archive out of sync, because the whole file will contain only one instance of "b". When b::m_a does not match what's in the archive, I'll just give up on loading and close the file.
However, I'm worried about other issues, like the ones mentioned in the tutorial under "Derived Classes": versioning problems, etc. Can I serialize with boost::serialization::base_object and deserialize with "&" ?
Now, what if b is derived from a instead of containing it? Would this work?
class b : public a { vector<int> m_v; // other data
template<class Archive> void save(Archive& ar, const unsigned version) const { ar & boost::serialization::base_object<a>(*this); ar & m_v; }
template<class Archive> void load(Archive& ar, const unsigned version) { a tmp; ar & tmp; if(tmp == static_cast< const a& >(*this)) ar & m_v; throw ??? // abort serialization }
// ... };
I would expect the above to do what think you want. Robert Ramey