user1361164
user1361164

Reputation: 51

Serialize function is not called

I am trying to debug save/load feature implemented with Boost serialization, but it doesn't work. I founded that the problem is caused by class tile:

class tile : public game_object {
...
friend class boost::serialization::access;
template <class Archive>
void serialization(Archive ar &, const unsigned int version) 
{
    throw new std::exception;    //I expect this will be thrown when serializing, but it isn't
    ar & boost::serialization::base_object<game_object>(*this);
    ...
}

Saving to archive:

boost::archive::text_oarchive archive(...);
tile t = ...;
archive << t;

Loading from archive:

boost::archive::text_iarchive archive(...);
tile t;
archive >> t;

The problem is, that data members from class tile which are not in class game_object are not saved and loaded. Function tile::serialize is never called, but function game_object::serialize is called.

Thanks for help and sorry for my english.

Upvotes: 0

Views: 252

Answers (1)

user1361164
user1361164

Reputation: 51

I have found the problem. The method to serialize should be called "serialize" instead of "serialization".

Upvotes: 1

Related Questions