Boost logo

Boost Users :

Subject: [Boost-users] [boost][Serialization] - about macro BOOST_CLASS_VERSION
From: girish hilage (girish_hilage_at_[hidden])
Date: 2011-01-07 00:42:12


Hi,
   I have a query regarding macro BOOST_CLASS_VERSION().
   I am running following code :
    class testRep
    {
        friend std::ostream & operator<<(std::ostream &os, const testRep &tr);
   
        public :
        template<class Archive> void serialize(Archive &ar, const unsigned int version)
        {
            if(version >= 2)
                ar & BOOST_SERIALIZATION_NVP(Site);
        }
        private :
            string Site;
    };
  
    BOOST_CLASS_VERSION(testRep, 2)
  
    std::ostream & operator<<(std::ostream &os, const testRep &tr)
    {
        return os << '\n' << tr.Site << endl;
    }
  
    void read_file (testRep &s, const char * filename)
    {
        std::ifstream ifs(filename);
        assert (ifs.good());
        boost::archive::xml_iarchive ia(ifs);
        ia >> BOOST_SERIALIZATION_NVP(s);
    }
    int main (void)
    {
        testRep tr;
        read_file (tr, "Test.xml");
        cout << tr << endl;
        return 0;
    }
   This code runs fine.
   But, if I remove the statement :
   BOOST_CLASS_VERSION(testRep, 2)
   
   then I get following error :
   terminate called after throwing an instance of 'boost::archive::archive_exception'
     what():  class version
   Aborted (core dumped)
   
   So, want to ask if it is mandatory to declare a macro BOOST_CLASS_VERSION()? and if not then how do I prevent this runtime error from happening?
 
Regards,
Girish



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