|
Boost Users : |
Subject: [Boost-users] [serialization] : compile problem
From: Kaz (sfx810_at_[hidden])
Date: 2011-08-20 11:53:25
Hi All,
I am trying to compile this code to test boost serialization, however
I am getting this error
Error 5 error C2664: 'boost::mpl::assertion_failed' : cannot convert
parameter 1 from 'boost::mpl::failed
************boost::serialization::is_wrapper<T>::* ***********' to
'boost::mpl::assert<false>::type' c:\program files
(x86)\boost\boost_1_46_1\boost\archive\basic_xml_oarchive.hpp 92
I am using boost 1.46.1, visual studio c++ 2010 express.
Any help will be appreciated.
Thanks,
Kaz
//-----------------------------------------------------------------------------------------------------------
#include <string>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/list.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/tmpdir.hpp>
#include <fstream>
class Base
{
friend class boost::serialization::access;
template<typename archive>
void serialize( archive& ar, const unsigned int version )
{
ar &
BOOST_SERIALIZATION_NVP(a) &
BOOST_SERIALIZATION_NVP(c) &
BOOST_SERIALIZATION_NVP (strBase);
}
public:
Base( int a_arg, char c_arg ) : a( a_arg ), c ( c_arg )
{ strBase = "This is base"; }
int a;
char c;
std::string strBase;
};
//-------------------------------------
BOOST_SERIALIZATION_ASSUME_ABSTRACT(Base)
//-------------------------------------
class Child : public Base
{
friend class boost::serialization::access;
template<typename archive>
void serialize( archive& ar, const unsigned int version )
{
ar & boost::serialization::base_object<Base>(*this);
ar & BOOST_SERIALIZATION_NVP(f) & BOOST_SERIALIZATION_NVP(strChildName);
}
public:
Child() : Base(0,'c'), f(3.3417)
{ strChildName = "This is Child"; }
float f;
std::string strChildName;
};
//-------------------------------------
class BaseContainer
{
typedef Base* BasePtr;
std::vector<BasePtr> BaseVec;
friend class boost::serialization::access;
template<typename archive>
void serialize( archive& ar, const unsigned int version )
{
ar.register_type<Base>();
ar.register_type<Child>() ;
ar & BaseVec;
}
public:
BaseContainer() {}
void Init()
{
for(int i = 0; i < 10; ++i )
{
if ( i < 5 )
BaseVec.push_back( new Base(i,'b') );
else
BaseVec.push_back( new Child() );
}
}
};
//-------------------------------------
int main()
{
std::string filename="demo.xml";
BaseContainer baseContainer;
baseContainer.Init();
{
std::ofstream ofile(filename);
boost::archive::xml_oarchive out(ofile);
out << BOOST_SERIALIZATION_NVP(baseContainer);
}
return 0;
}
//-------------------------------------
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