Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] Serialize shared_ptr compile error
From: elizabeta petreska (elizabeta.petreska_at_[hidden])
Date: 2009-11-25 09:48:34


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 <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");

  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



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