Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization]Serialization of nested stl object
From: Júlio Hoffimann (julio.hoffimann_at_[hidden])
Date: 2011-09-20 18:31:43


Hi Kangkook,

By removing the pointer in const string*, the code compiles. You have to
investigate how Boost.Serialization handles pointers to stdlib classes:

http://www.boost.org/doc/libs/1_47_0/libs/serialization/doc/index.html

I never tried to serialize a string* nor any pointer to a stdlib class
before. Although i know it's possible to use pointers for base classes
polymorphically. Serializing a string* shouldn't be a problem, i guess.

Regards,
Júlio.

2011/9/20 Kangkook Jee <aixer77_at_[hidden]>

> The following is the code snippet that wouldn't get compiled.
>
> #include <iostream>
> #include <fstream>
> #include <map>
> #include <string>
>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/archive/text_iarchive.hpp>
>
> #include <boost/serialization/map.hpp>
> #include <boost/serialization/set.hpp>
> #include <boost/serialization/string.hpp>
>
>
> using namespace std;
>
> class B {
> //private attributes
> map<const string* , set<unsigned> > lines;
>
> //serialization
> friend class boost::serialization::access;
>
> template<class Archive>
> void serialize (Archive & ar, const unsigned int version) {
> ar & lines;
> }
>
>
> public:
> B() {}
> };
>
> main (int argc, char* argv[]) {
>
> string fname(argv[1]);
>
> B b0;
>
> std::ofstream ofs (fname.c_str());
> boost::archive::text_oarchive oa(ofs);
> oa << b0;
> ofs.close();
>
> std::ifstream ifs(fname.c_str());
> boost::archive::text_iarchive ia(ifs);
> ia >> b0;
> ifs.close();
>
> return 0;
> }
>



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