1

I'm trying to create base of objects, which contains as attribute vector of object from different class. Here's my code:

    #include <iostream>
    #include <string>
    #include <vector>
    #include <fstream>
    #include <boost/archive/binary_oarchive.hpp>
    #include <boost/archive/binary_iarchive.hpp>

    using namespace std;

    class form_mesto
    {
    public:
        string mesto;
        int year;
        int mounth;
        int day;
        bool visit = false;
        form_mesto(string a_mesto)
        {
            mesto = a_mesto;
        }
    };

    class Place
    {
    private:
        friend class boost::serialization::access;
        template<class Archieve>
        void serialize(Archieve&ar, const unsigned int version)
        {
            ar& mestа;
            ar& person;
        }
    public:
        string person;
        vector<form_mesto> mestа;

        Place(string a_person)
        {
            person = a_person;
        }

        void add_place(form_mesto a_mesto)
        {
            mestа.push_back(a_mesto);
        }
    };

int main()
{
    string input_in_form = "London";
    string input_in_Place = "Eugene";
    form_mesto z = form_mesto(input_in_form);
    Place x = Place(input_in_Place);
    x.add_place(z);
    std::ofstream ofs("save.dat", std::ios::binary);
    boost::archive::binary_oarchive oa(ofs);
    oa<<x;
};

Error, which i get is:

c:\boost_1_57_0\boost\serialization\access.hpp(118): error C2039: serialize: is not a member of "std::vector>".

Can somebody share experience of how to serialize that type of objects?

1
  • what does it mean to "serialize as attribute" Commented Feb 27, 2015 at 10:15

1 Answer 1

1

To make the code compilable, one has to do the following:

  1. to include the header responsible for vector serialization

    #include <boost/serialization/vector.hpp>
    
  2. to add the serialize method to the form_mesto class

    class form_mesto
    {
    private:
        friend class boost::serialization::access;
        template<class Archieve>
        void serialize(Archieve&ar, const unsigned int version)
        {
            // ...
        }
    // ...
    };
    

Here is the compilable code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.