C++ Boost ptr_map序列化错误
我有一些想要构建的代码。 该代码使用 boost::ptr_map 类来序列化某些对象。 我有带有 boost1.38 的 Visual Studio 2008,但编译器出现以下错误。 我想知道是否还有人见过这样的事情。
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 << (*this);
}
catch(...)
{
throw;
}
return true;
}
};
int main()
{
User user;
user.save("C:\\test.db");
return EXIT_SUCCESS;
}
任何帮助都是值得赞赏的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来有一个
boost/ptr_container/serialize_ptr_map.hpp
,这对于 #include 可能很重要。It looks like there is a
boost/ptr_container/serialize_ptr_map.hpp
, that is probably important to #include.也许只是没有对 boost::ptr_map 的序列化支持? Boost 库并未以这种方式完全连接。 尝试在增强邮件列表上询问。
然而,编写一个函数来序列化 ptr_map 应该非常容易。
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.