Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;Boost ptr_映射序列化错误_C++_Stl_Boost Serialization - Fatal编程技术网

C++ C++;Boost ptr_映射序列化错误

C++ C++;Boost ptr_映射序列化错误,c++,stl,boost-serialization,C++,Stl,Boost Serialization,我有一些代码,我想建立。代码使用boost::ptr_映射类来序列化某些对象。我有VisualStudio2008和boost1.38,我从编译器中得到以下错误。我想知道是否有人见过这样的事情 C2039:“序列化”:不是“boost::ptr_map”的成员 看起来缺少了一些引用,我想知道它是什么,我没有看到任何boost/serialization/ptr_映射。我在谷歌上搜索了很多次,结果证明没有什么是可行的。我创建了一个示例代码,生成了下面相同的错误 #include <fstre

我有一些代码,我想建立。代码使用boost::ptr_映射类来序列化某些对象。我有VisualStudio2008和boost1.38,我从编译器中得到以下错误。我想知道是否有人见过这样的事情

C2039:“序列化”:不是“boost::ptr_map”的成员

看起来缺少了一些引用,我想知道它是什么,我没有看到任何boost/serialization/ptr_映射。我在谷歌上搜索了很多次,结果证明没有什么是可行的。我创建了一个示例代码,生成了下面相同的错误

#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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
类用户
{
boost::ptr_映射ptrmap;
公众:
好友类boost::serialization::access;
模板
无效序列化(存档和ar,常量未签名整数版本)
{
ar&ptrmap;
}
bool保存(const std::string和filename)
{
ofs流(filename.c_str());
如果(ofs.good()==false)
{
返回false;
}
尝试
{
boost::archive::text\u oarchive oa(ofs);

oa可能只是boost::ptr_映射没有序列化支持?boost lib没有以这种方式完全连接。请尝试在boost邮件列表中询问


但是,编写函数序列化ptr_映射应该很容易。

看起来有一个
boost/ptr_容器/serialize_ptr_映射.hpp
,这可能对#包括在内很重要。

我以前有一段代码已经成功编译过,我相信它是使用Visual Studio 2005(即我将要使用的VC8编译器)构建的将其发布到boost邮件列表中,请参见