C ++ Boost ptr_map序列化错误 [英] C++ Boost ptr_map serialization error

查看:215
本文介绍了C ++ Boost ptr_map序列化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,我想构建。代码使用boost :: ptr_map类来序列化某些对象。我有Visual Studio 2008与boost1.38和我从编译器得到以下错误。我不知道有没有人看过这样的东西。



C2039:'serialize':不是'boost :: ptr_map'的成员



看起来像一些参考缺少,我不知道是什么,我没有看到任何boost / serialization / ptr_map。我有谷歌很多,没有什么证明是可行的。我创建了一个示例代码,在下面生成相同的错误

  #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<< (*这个);
}
catch(...)
{
throw;
}

return true;
}
};


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

任何帮助。

解决方案

它似乎有一个 boost / ptr_container / serialize_ptr_map.hpp ,这可能是重要的#include。 / p>

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.

解决方案

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

这篇关于C ++ Boost ptr_map序列化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆