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@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Pavlo Korzhyk
Gesendet: Donnerstag, 26. Oktober 2006 16:09
An: boost-users@lists.boost.org
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
#include
#include
#include
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 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 m;
map 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