ar & boost::serialization::base_object(*this);
要不然,boost的serialization會丟出unregistered_cast的exception。
(即使B class根本沒有任何資料要serialize)
底下是簡單的範例
#include <boost/serialization/access.hpp>
class B
{
friend class boost::serialization::access;
template<class Archive> void serialize(Archive& ar, const unsigned int file_version)
{
}
};
class D : public B
{
friend class boost::serialization::access;
template<class Archive> void serialize(Archive& ar, const unsigned int file_version)
{
ar & boost::serialization::base_object(*this);
ar & value_;
}
private:
int value_;
};
沒有留言:
張貼留言