views:

387

answers:

2

I have some code that I want to build. The code uses boost::ptr_map class to serialize certain objects. I have Visual Studio 2008 with boost1.38 and I am getting following error from compiler. I wonder if any one else has seen any thing like this.

C2039: 'serialize' : is not a member of 'boost::ptr_map'

Looks like some reference is missing and I wonder what it is, I don't see any boost/serialization/ptr_map. I have Googled a lot and nothing has proved to be viable. I have created a sample code that generates the same error below

#include <fstream>
#include <iostream>


#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/config.hpp>

#include <boost/shared_ptr.hpp>
#include <boost/ptr_container/ptr_map.hpp>

#include <boost/serialization/string.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/split_member.hpp>

using namespace std;

class User
{
    boost::ptr_map<std::string, string> ptrmap;

public:

    friend class boost::serialization::access;

    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
     ar & ptrmap;
    }

    bool save(const std::string& filename)
    {
     ofstream ofs(filename.c_str());

     if(ofs.good() == false)
     {
      return false;
     }

     try
     {
      boost::archive::text_oarchive oa(ofs);
      oa << (*this);
     }
     catch(...)
     {
      throw;
     }

     return true;
    }
};


int main()
{
    User user;
    user.save("C:\\test.db");
    return EXIT_SUCCESS;
}

Any help is appreciated.

A: 

Maybe there just isn't serialization support for boost::ptr_map ? The Boost libs aren't fully connected that way. Try asking on the boost-mail list.

However, writing a function to serializing a ptr_map should be pretty easy.

Marcus Lindblom
I have this code which is successfully compiled before and I believe it was built using Visual Studio 2005 i.e. VC8 compilerI am going to post it on boost-mailing list too
Faheem
It does, see http://www.boost.org/doc/libs/1_39_0/libs/ptr_container/doc/reference.html#serialization
Greg Rogers
+1  A: 

It looks like there is a boost/ptr_container/serialize_ptr_map.hpp, that is probably important to #include.

Greg Rogers