带有自定义类存档的BOOST_CLASS_EXPORT_GUID

时间:2014-12-11 16:57:04

标签: c++ boost boost-serialization

我正在使用boost 1.49。我有来自boost二进制存档的自定义存档。但是,当使用BOOST_CLASS_EXPORT_GUID时,似乎实际上没有为自定义存档类型注册类型,并且在从基指针序列化派生类时,我收到了unregistered_class异常。如果我使用的是boost二进制原始档案,则情况并非如此。我的自定义归档类在其自己的头文件中定义,在文件末尾我包含BOOST_SERIALIZATION_REGISTER_ARCHIVE,根据文档http://www.boost.org/doc/libs/1_49_0/libs/serialization/doc/archive_reference.html#usage中的内容:

这是我的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) 

这里是每个我注册所有类的cpp文件:

#include "customarchive.h" 
#include <boost/serialization/export.hpp>
#include "A.h" 
BOOST_CLASS_EXPORT_GUID(A,"A") 

0 个答案:

没有答案