Hi all,
I'm trying to create a class with built in save and load methods that handles serializing and deserializing data to disk to persist the class. I've been able to get the save working, but I'm having some trouble with the load. I getting the below error.
error: Failure in UserObjectSerialization: Unhandled exception: class version
I've done some googling on it and can't find any documentation that seems to apply in my situation. I'm not using any of the versioning features built into boost, as this is mostly an experiment to get familar with the library.
The error is happening inside of a basic c++ Unit Test, copied below
TEST(UserObjectSerialization)
{
UserObjects::UserObject userobj;
boost::posix_time::ptime time = userobj.GetCreatedOn();
userobj.SetName("TestObj");
userobj.Save();
sleep(5);
UserObjects::UserObject loadedUserObj;
{
std::ifstream ifs("TestObj");
boost::archive::text_iarchive ia(ifs);
ia >> loadedUserObj;
}
The save method of the user object looks like this
void UserObject::Save()
{
std::ofstream ofs(_name.c_str());
{
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << this;
// archive and stream closed when destructors are called
}
}
The error is being thrown on the line "ia >> loadedUserObj" of the test method.
I can provide the full include and class definition file for the UserObject class if needed, but I didn't want to clutter up my message if it wasn't necessary. I can also post the contents of one of the files created during a sucessful save.
Does anyone have any advice on how to deal with this error? Thanks for your help.
~Andrew S.