Сериализация с использованием 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()'

person user976749    schedule 24.02.2012    source источник


Ответы (1)


  1. Включить <boost/serialization/vector.hpp>.
  2. Не выделяйте vector динамически.
  3. Не забудьте связать с Serialization, это не только библиотека заголовков.
person Cat Plus Plus    schedule 24.02.2012
comment
Цифра 2 должна быть написана большими жирными буквами. - person R. Martinho Fernandes; 24.02.2012