Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Archive reload
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-03-02 13:21:09


Should work without problem.

make sure you're including <boost/serialization/string.hpp>

Robert Ramey

Ferllings wrote:
> Hello,
>
> I have a Class A with string attributes that I serialize in XML
> format:
> Class A {
> public:
> string _nom;
> string _prenom;
> template<class Archive>
> void serialize(Archive& ar, const unsigned in version){
> ar & boost::serialization::make_nvp("Nom", _nom);
> ar & boost::serialization::make_nvp("Prenom", _prenom);
> }
> }
>
> The object is correctly saved using this code:
>
> A _a;
>
> void save() const
> {
> ...
> oTextArchive::xml_oarchive oTextArchive(ofile);
> oTextArchive << make_nvp("A", _a);
> ...
> }
>
> But I want to reload the object, the A attributes aren't updated and
> keep the previous values:
>
> void load()
> {
> ...
> iTextArchive::xml_oarchive iTextArchive(ifile);
> iTextArchive >> make_nvp("A", _a);
> ...
> }
>
> The only way I found to reload my object is to use an temporary
> object:
> void load()
> {
> ...
> A _tmp;
> iTextArchive::xml_oarchive iTextArchive(ifile);
> iTextArchive >> make_nvp("A", _tmp);
> _a = _tmp;
> ...
> }
>
> Why can't I update the object directly?
>
> Thanks for your help.


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