使用Boost.Serialization进行序列化 [英] Serialization using Boost.Serialization

查看:245
本文介绍了使用Boost.Serialization进行序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试序列化,但每次遇到错误,如: -

I have been trying serialization but every time I got stuck with errors like:-

error: 'class std::vector<int, std::allocator<int> >' has no member named 'serialize'

这里是我的源代码和serialize方法, am use boost.serialize

here is my source code and serialize method ,knowing I am use 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&生命值;到

then i changed this line ar & hp; into

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()'


推荐答案


  1. 包含< boost / serialization / vector.hpp>

  2. 不要分配

  3. 不要忘记将链接到序列化,而不是标题库。
  4. $ b $ b
  1. Include <boost/serialization/vector.hpp>.
  2. Don't allocate vector dynamically.
  3. Don't forget to link to Serialization, it's not header-only library.

这篇关于使用Boost.Serialization进行序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆