|
Boost Users : |
From: Oliver Mutz (omutz_at_[hidden])
Date: 2006-10-26 11:22:04
Might be a problem with uninitialized bool value. Look into your
text-archive if the bool value is 0 or 1.
Try initializing your bool member either to true or false and test again.
Regards,
Oliver
-----Ursprüngliche Nachricht-----
Von: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] Im Auftrag von Pavlo Korzhyk
Gesendet: Donnerstag, 26. Oktober 2006 16:09
An: boost-users_at_[hidden]
Betreff: [Boost-users] [boost.serialization] serialization crash
The following code crashes under cygwin+boost1.33 and under mingw+boost1.33
I create text archive in a file, and then serialization crashes when
restoring object from that archive.
The problem seem to be with bool field, if I replace
bool x;
with
int x;
in the class Obj implementation, everything runs fine.
Is this a bug in serialization code?
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <map>
using namespace std;
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
using namespace boost;
using namespace boost::serialization;
class Obj {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & x;
}
public:
bool x;
};
class Item;
class Cheq : public Obj{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<Obj>(*this);
ar & v;
ar & id;
}
public:
vector<Item> v;
int id;
Cheq(){}
};
class Item{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & a;
ar & s;
}
public:
int a;
string s;
};
class Row{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & m1;
ar & m2;
}
public:
map<string,string> m1,m2;
};
class Data{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & a;
ar & m;
ar & cheque;
}
public:
int a;
map<string,string> m;
map<int,Cheq> cheque;
};
BOOST_CLASS_TRACKING(Data, boost::serialization::track_never)
#include "boost/serialization/export.hpp"
BOOST_CLASS_EXPORT(Data);
BOOST_CLASS_EXPORT(Cheq);
BOOST_CLASS_EXPORT(Item);
int main(int argc, char** argv)
{
Data d;
d.cheque[0]=Cheq();
//if(argc>1 && argv[1][0]=='1')
{
ofstream os("datfile");
boost::archive::text_oarchive oar(os);
oar << d;
}
//if(argc>1 && argv[1][0]=='2')
{
ifstream is("datfile");
boost::archive::text_iarchive iar(is);
iar >> d;
}
cout << "without crash\n";
return 0;
}
-- WBR, Pavlo Korzhyk ICQ#155870780
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