使用Boost.Serialization进行序列化
Serialization using Boost.Serialization
我一直在尝试序列化,但每次都会遇到以下错误:-
error: 'class std::vector<int, std::allocator<int> >' has no member named 'serialize'
这是我的源代码和序列化方法,知道我正在使用boost.serialize
template <class E, class T>
class heap{
vector<E> * hp;
int index;//index is pointing to first empty place after the last element
int maxsize;
T comp;//comparable object designed to compare the objects
private:
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & hp;
ar & index;
ar & maxsize;
ar & comp;
}
public:
//default empty constructor
heap(){
hp = new vector<E>(MAX);
index = 0;
maxsize = MAX;
}
.
.
.
.
.
.
}
然后我改变了这行ar&hp;进入
for(int i = 0; i < hp->size(); i++)
ar & hp->at(i);
我犯了更严重的错误,比如
/../../../../boost/boost_1_48_0/boost/archive/text_oarchive.hpp:100: undefined reference to `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::ostream&, unsigned int)'
debug/main.o: In function `~text_oarchive_impl':
Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/archive/text_oarchive.hpp:85: undefined reference to `boost::archive::basic_text_oprimitive<std::ostream>::~basic_text_oprimitive()'
Qt_4_8_0__4_8_0__Debug/../../../../boost/boost_1_48_0/boost/archive/text_oarchive.hpp:85: undefined reference to `boost::archive::basic_text_oprimitive<std::ostream>::~basic_text_oprimitive()'
- 包括
<boost/serialization/vector.hpp>
- 不要动态分配
vector
- 不要忘记链接到Serialization,它不是只有头的库
相关文章:
- 如何在C++中序列化结构数据
- 序列化,没有库的整数,得到奇怪的结果
- 如何知道QDataStream不能反序列化某些内容
- 如何使用Python从C++中读取谷物序列化数据
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- 自定义对象的dlib序列化在gcc中失败
- C++boost序列化多态性问题
- 增强基于 XML class_id的反序列化
- 提升反序列化对象具有 nan 或 -nan 值
- 在 cpp 中的平面缓冲区中序列化对象
- 每次进行继承时都需要提升::序列化::base_object吗?
- 如何在 c++ 非托管代码中反序列化 byte[] 的 json 字符串?
- 提升序列化 1:73 的向后兼容性问题
- 将 boost 序列化对象的 asio::streambuf 表示转换为 Beast 的 DynamicBody req.body()
- 为什么 nlohmann/json 序列化 "null" 而不是在 double 上"0"?
- 如何反序列化数组?
- 如何使用提升序列化?
- 序列化多晶型接口
- FlatBuffers/Protobuf 中是否有支持任意 24 位有符号整数定义的可移植二进制序列化架构?