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 :
/////A.h
#pragma once
#include
#include
#include
#include
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");
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);
}
}
And I am getting the following compile time error :
'boost::mpl::assertion_failed' : cannot convert parameter 1 from
'boost::mpl::failed ************boost::serialization::is_wrapper<T>::*
***********' to 'boost::mpl::assert<false>::type'
D:\main\dev\sdk\libs\boost\inc\boost-1_38\boost\archive\basic_xml_oarchive.hpp
88
The comment about the erroir says :
// If your program fails to compile here, its most likely due to
// not specifying an nvp wrapper around the variable to
// be serialized.
I can't understand what does it mean, since I have BOOST_SERIALIZATION_NVP
when writing /reading to the archive