C++ shared_ptr serialization
C++ shared_ptr serialization
我有一个名为 A 的类,我想在另一个名为 B 的类中序列化它的对象,但我不断收到此错误:
error: ‘class std::shared_ptr<A>’ has no member named ‘serialize’
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;
}
和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 & test;
}
friend class boost::serialization::access;
}
请注意,这里shared_ptr是指 std::shared_ptr,而不是 boost::shared_ptr。 事实上,我使用了这一行: 使用命名空间 std; 在我的 A 类之前
你可能忘了包含
#include <boost/serialization/shared_ptr.hpp>
您需要 shared_ptr.hpp 和 boost 版本 1.56 的组合
相关文章:
- CLANG 编译器 说:变量"PTR"可能未初始化
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 为共享 ptr 向量实现复制 c'tor?
- 字符和整数中 **(ptr+1) 的值差异
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何将派生类从基 ptr 分配给 nlohmann::json
- 引用 std::shared:ptr 以避免引用计数
- 我在使用 boost::serialization 时遇到了一个问题,我的代码在 Linux 中运行良好,但在 Wind
- 为什么我不能在不进行任何转换的情况下将浮点数放入任何类型的 ptr 中?
- 在调用函数时,ptr** 和 ptr*& 之间是否有区别,或者首选C++?
- 另一种类型的智能ptr,比如具有弱refs的unique_ptr
- 尝试打印出 *ptr++ 的值,以了解它是如何工作的
- 如何控制共享 ptr 引用计数?
- C++中的指针否定 (!ptr == NULL)
- 从const ptr*转换为ptr*时出现问题
- 使用 Boost::Serialization 序列化具有 std::mt19937_64 成员的类
- 这是MSVC 2013中具有共享PTR的单例的正确实现吗?
- 对唯一 ptr 无效读取的引用向量
- C++ 类型转换基础 PTR 到派生 PTR 保存在引用类中