I have to serialize libkdtree++ in my program, the tree structures are briefly described as following:
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 "stream error". But from the "serailzed file", it lacks the value fields for the children nodes of roots. Thus I think it is possible that BaseNode serialized _M_left and _M_right pointer. However since _Node_base have no idea about the value type of _Node, so it looks hard to add "ar.register_type" to _Node_base.serialize().