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

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

问题描述

我一直在试图序列化,但每一次我被困像错误: -

 错误:'类的std ::矢量<整型,性病::分配器< INT> >'没有成员名为连载

这是我的源$ C ​​$ c和序列化的方法,知道我使用boost.serialize

 模板< E类,类T>
类堆{    矢量< E> * 生命值;
    //指数的最后一个元素后指向第一个空的地方; INT指数
    INT MAXSIZE;    ŧ补偿; //可比对象设计比较对象私人的:
    友元类的boost ::系列化::访问;
    //当类归档对应到一个输出档案中,
    //&安培;操作员被定义相似至<&所述;.同样地,当类存档
    //是一种类型的输入存档和放大器;操作员被定义相似到大于取代。
    模板<类归档和GT;
    无效连载(归档和放大器; AR,const的无符号整型版)
    {        AR&安培;生命值;
        AR&安培;指数;
        AR&安培; MAXSIZE;
        AR&安培;补偿;
    }上市:
    //默认的空构造函数
    堆(){        HP =新的矢量< E>(MAX);
        索引= 0;
        MAXSIZE = MAX;
    }






}

然后我改变了这一行AR&安培;生命值;到

 的for(int i = 0; I< HP-GT&;尺寸();我++)
   AR&安培; HP->对于(ⅰ);

我更惨错误,如

  /../../../../提升/ boost_1_48_0 /升压/存档/ text_oarchive.hpp:100:未定义引用`boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::ostream&,无符号整数)'
调试/ main.o中:在功能`〜text_oarchive_impl:Qt_4_8_0__4_8_0__Debug /../../../../提升/ boost_1_48_0 /升压/存档/ text_oarchive.hpp:85:未定义的引用`的boost ::存档:: basic_text_oprimitive&LT;的std :: ostream的&GT; ::〜basic_text_oprimitive( )Qt_4_8_0__4_8_0__Debug /../../../../提升/ boost_1_48_0 /升压/存档/ text_oarchive.hpp:85:未定义的引用`的boost ::存档:: basic_text_oprimitive&LT;的std :: ostream的&GT; ::〜basic_text_oprimitive( )


解决方案

  1. 包含&LT;升压/系列化/ vector.hpp方式&gt;

  2. 请不要分配矢量动态。

  3. 请不要忘记的链接的系列化,它不是仅邮件头库。

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'

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;


    }
.
.
.
.
.
.
}

then i changed this line ar & hp; into

for(int i = 0; i < hp->size(); i++)
   ar & hp->at(i);

I got even worse errors like

/../../../../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. 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天全站免登陆