|
Boost Users : |
From: Andreas Sæbjørnsen (andreas.saebjoernsen_at_[hidden])
Date: 2006-01-13 21:20:27
Hi,
I am currently experimenting with writing a compiler tool which generates
the code necessary for using boost::serialization. While working on this I
found that I am unable to serialize a variable declaration which is a
reference to a class constructed with the default constructor '()'( ex.
class foo var(); ). I have tried to find an explanation for this in the
examples, documentation and through searching the web without success. Using
pointers it works fine with the
default constructor and I do not see why it should be any different for
references (as references in essence are pointers). Is it possible to
serialize a class constructed using the default constructor using
boost::serialization, and if so how?
Example:
#include <fstream>
// include headers that implement a archive in simple text format
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
class gps_set
{
friend class boost::serialization::access;
public:
int x;
gps_set::gps_set(){ x = 2;};
virtual gps_set::~gps_set(){};
gps_set::gps_set(int i) : x(1) {};
private:
template<typename Archive>
void serialize(Archive& ar, const unsigned int version){
ar& x;
}// End method: X::serialization
};
int main()
{
// save the schedule
std::ofstream ofs("filename");
// create class instance
//Compile time error if s1() is used. No error if s1(1) is used.
const gps_set s1();
// save data to archive
{
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << s1;
// archive and stream closed when destructors are called
}
};
Thanks,
Andreas Saebjoernsen
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