[boost][Serialization] - about macro BOOST_CLASS_VERSION
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
participants (1)
-
girish hilage