C++ 使用Boost.Serialization进行序列化

C++ 使用Boost.Serialization进行序列化,c++,serialization,boost,vector,boost-serialization,C++,Serialization,Boost,Vector,Boost Serialization,我一直在尝试序列化,但每次都会遇到以下错误:- error: 'class std::vector<int, std::allocator<int> >' has no member named 'serialize' 错误:“class std::vector”没有名为“serialize”的成员 这是我的源代码和序列化方法,我知道我正在使用boost.serialize template <class E, class T> class heap{

我一直在尝试序列化,但每次都会遇到以下错误:-

error: 'class std::vector<int, std::allocator<int> >' has no member named 'serialize'
错误:“class std::vector”没有名为“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;


    }
.
.
.
.
.
.
}
模板
类堆{
向量*hp;
int index;//索引指向最后一个元素后的第一个空位置
int-maxsize;
T comp;//设计用于比较对象的可比较对象
私人:
好友类boost::serialization::access;
//当类归档对应于输出归档时
//运算符的定义类似于。
模板
无效序列化(存档和ar,常量未签名整数版本)
{
ar&hp;
ar&index;
ar&maxsize;
应收及应付帐款;
}
公众:
//默认空构造函数
堆(){
hp=新向量(最大值);
指数=0;
最大尺寸=最大值;
}
.
.
.
.
.
.
}
然后我改变了这一行ar&hp;进入

for(int i = 0; i < hp->size(); i++)
   ar & hp->at(i);
for(int i=0;isize();i++)
应收账款和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/boost\u 1\u 48\u 0/boost/archive/text\u oarchive.hpp:100:对“boost::archive::text\u oarchive\u impl::text\u oarchive\u impl(std::ostream&,unsigned int)”的未定义引用
debug/main.o:在函数`~text\u oarchive\u impl'中:
Qt_4_8_0_4_8_0_调试/../../../../../../boost/boost\u 1_48_0/boost/archive/text\u oarchive.hpp:85:对“boost::archive::basic\u text\u oprimitive::~basic\u text\u oprimitive()”的未定义引用
Qt_4_8_0_4_8_0_调试/../../../../../../boost/boost\u 1_48_0/boost/archive/text\u oarchive.hpp:85:对“boost::archive::basic\u text\u oprimitive::~basic\u text\u oprimitive()”的未定义引用
  • 包括
  • 不要动态分配
    vector
  • 别忘了链接到序列化,它不是唯一的头库

  • 数字2应该用大写字母。