BOOST_CLASS_EXPORT_GUID with custom class archive
I am using boost 1.49. I have custom archives obtained from binary archives. However, it seems that when using BOOST_CLASS_EXPORT_GUID, the types are not actually registered for the custom archive types, and I get an unregistered_class exception when serializing the derived class from the base pointer. If I use the boost binary source archives it is not. My own archive classes are defined in its own header file and at the end of the file I include BOOST_SERIALIZATION_REGISTER_ARCHIVE, according to this in the documentation http://www.boost.org/doc/libs/1_49_0/libs/serialization/doc/archive_reference.html #usage :
here is my customarchive.h:
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_oarchive_impl.hpp>
#include <boost/archive/binary_iarchive_impl.hpp>
#include <boost/archive/shared_ptr_helper.hpp>
class CloneBinaryIArchive :
// don't derive from binary_oarchive !!!
public boost::archive::binary_iarchive_impl<
CloneBinaryIArchive,
std::istream::char_type,
std::istream::traits_type
>,
public boost::archive::detail::shared_ptr_helper
{
typedef CloneBinaryIArchive derived_t;
typedef boost::archive::binary_iarchive_impl<
CloneBinaryIArchive,
std::istream::char_type,
std::istream::traits_type
> base_t;
public:
CloneBinaryIArchive(std::istream & is,unsigned int flags = 0) :
base_t(is, flags)
{}
CloneBinaryIArchive(std::streambuf & bsb, unsigned int flags = 0) :
base_t(bsb, flags)
{}
int foo;
};
BOOST_SERIALIZATION_REGISTER_ARCHIVE(CloneBinaryIArchive)
and here is the cpp file in each one I register all the classes:
#include "customarchive.h"
#include <boost/serialization/export.hpp>
#include "A.h"
BOOST_CLASS_EXPORT_GUID(A,"A")
source to share
No one has answered this question yet
Check out similar questions: