I need to serialize libkdtree ++ in my program, tree structures are briefly described as follows:
struct _Node_base {
_Node_base * _M_parent, *_M_left, * _M_right;
template<Archive>
serialize(Archive &ar, const unsigned int version) {
ar & _M_left & _M_right;
}
}
template<typename V>
struct _Node : public _Node_base {
typedef V value_type;
value_type value;
template<Archive>
serialize(Archive &ar, const unsigned int version) {
ar.register_type(static_cast<_Node*>(NULL));
ar & boost::serialization::base_object<_Node_base>(*this);
ar & value;
}
}
struct Tree {
_Node * root;
template<Archive>
serialize(Archive &ar, const unsigned int version) {
ar & root;
}
}
This program reports a stream error. But from the "serailzed file", it lacks value fields for child root nodes. Thus, I think it is possible that BaseNode serializes the _M_left and _M_right pointer. However, since _Node_base has no idea about the type of the _Node value, it is therefore difficult to add "ar.register_type" to _Node_base.serialize ().
source
share