|
Boost Users : |
Subject: Re: [Boost-users] serialization deserialization through the pointer
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-01-30 11:16:43
add friend class boost::serialization::access as described in the documentation.
Robert Ramey
"niranjan bangera" <niranjannina_at_[hidden]> wrote in message news:50a2f6f20901300052l51828b3cp4e885df559ad4299_at_mail.gmail.com...
hi all,
i am facing some problem in my code. Please help me to tackle it.
BOOST Version : 1.36.0
compliler : gnu-gcc-/4.1.1-binutils-2.16.1/x86_64-pc-linux2.4/bin/gcc
example of my prog:
header:
my.h
----
class my
{
int var1;
int var2;
structure object; // structure is the some other structure which is defined(i have defied the serialization function for this also...
/*serialization function*/
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int file_version)
{
ar & var1;
ar & var2;
ar & object;
}
};
mymain.cpp
----------
#include "boost/archive/text_iarchive.hpp"
#include "boost/archive/text_oarchive.hpp"
#include "boost/serialization/access.hpp"
#include "boost/serialization/serialization.hpp"
#include "boost/serialization/collection_traits.hpp"
#include "boost/serialization/utility.hpp"
#include "my.h"
class mymain
{
protected:
my * ptr;
public:
void mytake_arch();
void myretrive_arch();
};
void mymain::mytake_arch()
{
std::ofstream ofs("filename");
{
boost::archive::text_oarchive oa(ofs);
oa << ptr;
}
}
void mymain::myretrive_arch()
{
mymain *ptr = NULL; //// Confused in this, This is correct or wrong, if wront what else i can use
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
ia >> ptr;
}
int main()
{
mymain obj;
obj.mytake_arch();
obj.myretrive_arch();
}
Problem:
-------
I have some confusion in retriving, Whether the way in which i retrieved is correct or wrong. Any other replacement or modification can be done for the retriving part(myretrive_arch() function). Please let me know. because the retrived ptr(pointer retrived) causes segmentation fault whenenver i use it for some other application.
Any suggestions will be apprciated.
Thanks,
Niranjan
------------------------------------------------------------------------------
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
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