Hello everyone. I tried to serialize vector that is held
by pimpl but
I met to a lot of error. If someone who knows the resason for it exists,
please teach
me the reason. source code is below. Compiled using visual studio 2005
sp1 in WindowsXP64bit.
boost-1_34_1
source code has been attached.
// test_serialization.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <typeinfo>
#include <memory>
#include <algorithm>
#include <vector>
#include <map>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BOOST_LIB_NAME boost_serialization
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace boost;
using namespace boost::serialization;
namespace test{
class holder
{
struct Impl
{
Impl() : x(0.0), y(0.0), message(wstring(L"blank")) {
vec.push_back(shared_ptr<int>( new int(1) ));
vec.push_back(shared_ptr<int>( new int(2) ));
vec.push_back(shared_ptr<int>( new int(3) ));
}
Impl(
double ax,
double ay,
const wstring &am,
const vector &av )
: x(ax), y(ay), message(am), vec(av) {
}
double x, y;
wstring message;
vector vec;
private:
friend class serialization::access;
template <class Archive>
void serialize( Archive &ar, const unsigned long version );
};
shared_ptr<Impl> impl;
public:
holder() : impl( new Impl ) {}
holder(
double ax,
double ay,
const wstring &am,
const vector &av )
: impl( new Impl(ax, ay, am, av) ) {}
private:
friend class serialization::access;
template <class Archive>
void serialize( Archive &ar, const unsigned long version )
{
ar & impl;
}
};
template <class Archive>
void holder::Impl::serialize(Archive &ar, const unsigned long version ) {
ar & x; // ok
ar & y; // ok
ar & message; // ok
ar & vec; // error : if remove this line, this source code will move file.
}
template void holder::serializearchive::text_woarchive(
archive::text_woarchive &ar,
const unsigned long version );
template void holder::serializearchive::text_wiarchive(
archive::text_wiarchive &ar,
const unsigned long version );
template void holder::Impl::serializearchive::text_woarchive(
archive::text_woarchive &ar,
const unsigned long version );
template void holder::Impl::serializearchive::text_wiarchive(
archive::text_wiarchive &ar,
const unsigned long version );
}; // end namespace test2
int _tmain(int argc, _TCHAR* argv[])
{
using namespace test;
{
wofstream ofile( L"hierarchy.txt" );
archive::text_woarchive oa(ofile);
holder h;
oa << (const holder&)h;
ofile.close();
holder ih;
wifstream ifile( L"hierarchy.txt" );
archive::text_wiarchive ia(ifile);
ia >> ih;
ifile.close();
};
getchar();
return 0;
}