Boost logo

Boost Users :

Subject: [Boost-users] Can't serialize anything other than int or char
From: Tony Camuso (tcamuso_at_[hidden])
Date: 2015-03-05 19:29:53


Very simple case. I just need to know what I'm doing wrong.

#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

class foo
{
public:
        int bar;
        char *name;

        template<class Archive>
         void serialize(Archive &ar, const unsigned int version)
         {
                ar & name;
        }
};

void write_foo(foo *f)
{
        ofstream ofs("foo.txt");
        {
                boost::archive::text_oarchive oa(ofs);
                oa << f;
        }
}

The above fails to compile with the following error.

/usr/include/boost/serialization/access.hpp:118:9: error: request for member 'serialize' in 't', which is of non-class type 'char'
          t.serialize(ar, file_version);

If I replace the char pointer "name" with the int "foo", it works.
Should I be using something other than boost::archive::text_oarchive?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net