I am trying to serialize a vector of polymorphic pointers. My code looks as
follows:
class ASTNode{
...
protected:
vector children;
string name;
string type;
private:
// Code for serialization
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, unsigned int version)
{
ar & name;
ar & type;
ar & children;
}
}
class ASTNode2: public ASTNode{
...
private:
// Code for serialization
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, unsigned int version)
{
// serialize base class information
ar & boost::serialization::base_object<ASTNode>(*this);
}
// End code for serialization
}
I use the vector "children" to hold pointers to both base and derived
objects. I have tried registering the derived classes at the top of the
serialize function call, with the use of
ar.register(static_cast(NULL)).
I have also tried using the BOOST_CLASS_EXPORT_GUID macro to register the
classes in main. Yet, I still get a unregistered class exception. Any
guidance would be greatly appreciated.