Hi
I got a access violation on 0x00000000 with the class DDD but I cannot
figure
out what's wrong
When the symbol NO_EXCEPTION is defined, the member acccode is set to an
instance of ACCCODE and the serialization is working fine. But when this
symbol is undefined, one gets the exception.
I am suspecting the input serialization to bypass the loading of the member
FIELD* field (which is following the "acccode" member)
which leads to an exception when the next member DISP* disp is loaded
but I have no way to check it out
any idea??
Francis
Source code below and also joined in annex
----------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include
#include
using namespace std;
class FIELD : public string {
private:
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const FIELD&);
template<class Archive>
void serialize(Archive &ar, const unsigned int version) {
ar & boost::serialization::base_object<string>(*this);
ar & member;
}
private:
string member;
FIELD(){}
public:
FIELD(const string& name): string(name){}
};
class DDD {
private:
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const DDD& dd);
template<class Archive>
void serialize(Archive &ar, const unsigned int version) {
ar & acccode;
ar & field;
ar & disp;
}
public:
DDD():
acccode(0),
disp(0),
field(0)
{}
class ACCCODE {
private:
friend class boost::serialization::access;
friend std::ostream & operator<<(
std::ostream &os, const ACCCODE&
);
template<class Archive>
void serialize(Archive &ar, const unsigned int version) {
ar & acccode;
}
public:
string acccode;
ACCCODE(){}
ACCCODE(const string& s) : acccode(s) {}
};
class DISP {
private:
friend class boost::serialization::access;
friend std::ostream & operator<<(
std::ostream &os, const DISP&
);
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & disp;
}
public:
string disp;
DISP(){}
DISP(const string& s) : disp(s) {}
};
public:
ACCCODE* acccode;
FIELD* field;
DISP* disp;
};
int main(int argc, char* argv[]) {
DDD ddd;
#ifdef NO_EXCEPTION
ddd.acccode = new DDD::ACCCODE("a");
#endif
ddd.field = new FIELD("BAR");
ddd.disp = new DDD::DISP();
const char* file = "TEST.txt";
{
std::ofstream os(file);
boost::archive::text_oarchive oa(os);
oa << ddd;
}
{
std::ifstream is(file);
boost::archive::text_iarchive ia(is);
ia >> ddd;
}
}
----------------------------------------------------------------------------
--
A good friend will come bail you out of jail..........
but, a true friend....will be sitting next to you saying:
"...that was fun."
begin 666 test_serialization.cpp
M(VEN8VQU9&4@/&EOF-H:79E+W1E'1?;V%R8VAI=F4N:'!P/@T*=7-I;F<@
M;F%M97-P86-E('-T9#L-"@T*8VQAF4H07)C:&EV
M92 F87(L(&-O;G-T('5NF%T:6]N.CIB87-E7V]B:F5C=#QS=')I;F<^*"IT
M:&ES*3L-"@D)"6%R("8@;65M8F5R.PT*"0E]#0H)<')I=F%T93H-"@D)PT*"0D)87(@)B!A8V-C;V1E.PT*"0D)87(@)B!F:65L9#L-"@D)"6%R("8@
M9&ES<#L-"@D)?0T*"7!U8FQI8SH-"@D)1$1$*"DZ#0H)"0EA8V-C;V1E*# I
M+ T*"0D)9&ES<"@P*2P-"@D)"69I96QD*# I#0H)"0E[?0T*"0EC;&%SPT*"0D)"0EAPT*"0D)<')I=F%T93H-"@D)"0EF'1?
G:6%R8VAI=F4@:6$H:7,I.PT*"0EI82 ^/B!D9&0[#0H)?0T*?0T*
`
end