Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-05-01 17:40:56


Hmmm - it looks like ASTNode might not be polymorphic - it doesn't seem
tohave a virtual function defined.

Try the following change:
"Juan Quiroz" <juancq_at_[hidden]> wrote in message
news:f4e027970605011410p207777c1m1abef4f5771acc07_at_mail.gmail.com...

I am trying to serialize a vector of polymorphic pointers. My code looks as
follows:

class ASTNode{
...
protected:
vector <ASTNode*> 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;
        }
        virtual ~ASTNode(); // <== try adding this in!
}
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<ASTNode*>(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.

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net