Question

I'm using boost::serialization, following is my class and I tried to serialize this class object in the main function.

#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <map>
#include <sstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/access.hpp>
#include <boost/static_assert.hpp>

using namespace boost;
using namespace std;

class gps_position
{
        public:
        int i ;
        int j;
        friend class boost::serialization::access;
        template<class Archive>
        void serialize(Archive &ar, const unsigned int version)
        {
                ar & i;
                ar & j;
        }

        gps_position(){};
        gps_position(int a, int b):i(a), j(b){};
};

int main()
{
        std::stringstream ss;
         boost::archive::text_oarchive ar( ss );
         gps_position obj(10, 20);
         ar << obj;
        return 0;
}

But I'm getting following compilation errors:

/usr/include/boost/archive/detail/oserializer.hpp: In function 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = gps_position]':
/usr/include/boost/archive/basic_text_oarchive.hpp:78:   instantiated from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = gps_position, Archive = boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/interface_oarchive.hpp:78:   instantiated from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = gps_position, Archive = boost::archive::text_oarchive]'
client.cpp:70:   instantiated from here
/usr/include/boost/archive/detail/oserializer.hpp:567: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'

following are the boost libraries are installed on my system:

boost-debuginfo-1.33.1-15.1.el5
boost-debuginfo-1.33.1-15.1.el5
boost-devel-1.33.1-15.1.el5
boost-1.33.1-15.1.el5
boost-1.33.1-15.1.el5
boost-doc-1.33.1-15.1.el5
boost-devel-1.33.1-15.1.el5 

Any pointer to resolve these compilation errors?

Was it helpful?

Solution

Try declaring

const gps_position obj(10, 20);

As suggested here;

boost version 1.33 is crazy old, I don't think any of us are going to easily reproduce.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top