Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top