|
Boost Users : |
Subject: Re: [Boost-users] [Serialization] Serialize shared_ptr compile error
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-11-25 12:03:51
"elizabeta petreska" <elizabeta.petreska_at_[hidden]> wrote in message
news:ff8898bd0911250648l9bdd3a3g47408714e88bebf3_at_mail.gmail.com...
Hello
I can't compile my simple project for serializing shared_ptr . I read the
archives and google it and still can't compile it :)
I am doing the following :...
I compiled your program slightly modified on my boost 1.41 system with no
problems:
/////A.h
#pragma once
#include <fstream>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/shared_ptr.hpp>
class A
{
public:
A(int k):
mk(k)
{}
A(){}
template<class Archive>
void save(Archive & ar, const unsigned int version) const
{
using boost::serialization::make_nvp;
ar & BOOST_SERIALIZATION_NVP(mk);
}
template<class Archive>
void load(Archive & ar, const unsigned int version)
{
using boost::serialization::make_nvp;
ar & BOOST_SERIALIZATION_NVP(mk);
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
int mk;
};
BOOST_SERIALIZATION_SHARED_PTR(A)
///func.cpp
//#include "A.h"
void func()
{
//std::ofstream ofs(L"C:\\boostarchiveSharedPtr.xml");
//std::ifstream ifs(L"C:\\boostarchiveSharedPtr.xml");
std::ofstream ofs("C:\\boostarchiveSharedPtr.xml");
std::ifstream ifs("C:\\boostarchiveSharedPtr.xml");
boost::shared_ptr<A> bPtr(new A(13));
{
using boost::serialization::make_nvp;
boost::archive::xml_oarchive oa(ofs);
oa & BOOST_SERIALIZATION_NVP(bPtr);
}
boost::shared_ptr<A> rbPtr;
{
using boost::serialization::make_nvp;
boost::archive::xml_iarchive ia(ifs);
ia & BOOST_SERIALIZATION_NVP(rbPtr);
}
}
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