I forgot to include more details on the ASTNode class, it's actually like this:

class ASTNode
{
    public:
        ASTNode(string _type="", string _name="", string _value="", string _type_specifier="");
        virtual ~ASTNode();

        virtual void Code_Gen();
        virtual void DumpOut(FILE *);
...
       void setName(string _name);
        void clear();

    protected:
        string name;
        string type;
        string type_specifier;
        string value;
        // Children nodes
        vector<ASTNode *> children;

    private:

        // Code for serialization
        friend class boost::serialization::access;
        template<class Archive>
        void serialize(Archive & ar, unsigned int version)
        {
            ar & name;
            ar & type;
            ar & type_specifier;
            ar & value;
            ar & children;
        }
};

The derived classes implement the CodeGen and DumpOut methods.
Thank you for your prompt reply!


On 5/1/06, Robert Ramey <ramey@rrsd.com> wrote:
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@gmail.com > wrote in message
news:f4e027970605011410p207777c1m1abef4f5771acc07@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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users