嗨有任何人已经设法使用boost :: serialization序列化C++ 11 std :: shared_ptr.有很多过时的帖子,但没有一个可接受的解决方案.我不打算讨论为什么我要使用std :: shared_ptr只是接受它!
我发现了另一篇帖子:boost serialize和std :: shared_ptr但它没有回答我的问题如何序列化std :: shared_ptr它只建议使用boost :: shared_ptr,这在我的情况下是不可能的.
这篇文章如何将boost :: serialization与来自C++ 11的std :: shared_ptr一起使用?也建议只使用boost :: shared_ptr.
如果有人已经找到了解决std :: shared_ptr序列化问题的工作,我会感兴趣.
嘿家伙我终于找到了我的问题的解决方案,请参阅/sf/answers/1049957751/获取我的答案.
boost序列化库是否支持std :: unique_ptr的序列化?我试着编译下面的代码,但如果我包含 boost :: archive :: text_oarchive oa(ofs); oa << g; 线,
编译器(btw gcc4.7与-std = c ++ 11标志)抛出错误
/usr/include/boost/serialization/access.hpp:118:9:错误:'class std :: unique_ptr'没有名为'serialize'的成员
#include <iostream>
#include <memory>
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
class MyDegrees
{
public:
void setDeg(int d){deg = d;}
int getDeg()const {return deg;}
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{ ar & deg; }
int deg;
};
class gps_position
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & …Run Code Online (Sandbox Code Playgroud) 我有一个名为A的类,我想将它的对象序列化到另一个名为B 的类中。但我不断收到此错误:
error: ‘class std::shared_ptr<A>’ has no member named ‘serialize’
Run Code Online (Sandbox Code Playgroud)
A类是:
class A
{
public:
typedef shared_ptr<A> Ptr;
string name;
Predicate(const string &name = ""):name(name)
{}
private:
template<typename Archive>
void serialize(Archive& archive, const unsigned int v)
{
archive & name;
}
friend class B;
friend class boost::serialization::access;
}
Run Code Online (Sandbox Code Playgroud)
和B类:
class B
{
public:
typedef unordered_set<A::Ptr,
APtrKeyHash,
APtrKeyEq> A_set_t;
A_set_t test;
private:
template<typename Archive>
void serialize(Archive& archive, const unsigned int v)
{
archive & …Run Code Online (Sandbox Code Playgroud)