Boost logo

Boost Users :

From: Francis ANDRE (francis.andre_at_[hidden])
Date: 2004-10-02 12:07:39


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 <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
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@/&EO<W1R96%M/@T*(VEN8VQU9&4@/&9S=')E86T^#0HC:6YC
M;'5D92 \8F]O<W0O87)C:&EV92]T97AT7VEA<F-H:79E+FAP<#X-"B-I;F-L
M=61E(#QB;V]S="]A<F-H:79E+W1E>'1?;V%R8VAI=F4N:'!P/@T*=7-I;F<@
M;F%M97-P86-E('-T9#L-"@T*8VQA<W,@1DE%3$0_at_.B!P=6)L:6,@<W1R:6YG
M('L-"@EP<FEV871E._at_T*"0EF<FEE;F0_at_8VQA<W,@8F]O<W0Z.G-E<FEA;&EZ
M871I;VXZ.F%C8V5S<SL-"@D)9G)I96YD('-T9#HZ;W-T<F5A;2 F(&]P97)A
M=&]R/#PH<W1D.CIO<W1R96%M("9O<RP_at_8V]N<W0_at_1DE%3$0F*3L-"@D)=&5M
M<&QA=&4\8VQA<W,@07)C:&EV93X-"@D)=F]I9"!S97)I86QI>F4H07)C:&EV
M92 F87(L(&-O;G-T('5N<VEG;F5D(&EN="!V97)S:6]N*2![#0H)"0EA<B F
M(&)O;W-T.CIS97)I86QI>F%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)<W1R
M:6YG(&UE;6)E<CL-"@D)1DE%3$0H*7M]#0H)<'5B;&EC._at_T*"0E&245,1"AC
M;VYS="!S=')I;F<F(&YA;64I.B!S=')I;F<H;F%M92E[?0T*?3L-"@T*#0IC
M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6$H:7,I.PT*"0EI82 ^/B!D9&0[#0H)?0T*?0T*
`
end

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