在boost中使用polymorphic_text_archive序列化一个primitive_type类

时间:2011-08-16 14:39:13

标签: c++ boost-serialization

我正在尝试测试以下示例代码,该代码解释了如何在boost中序列化用户定义的基本类型类,它工作正常。但是如果我切换到polymorphic_archive(使用polymorphic_text_ *测试),我将不得不在我的项目,它无法编译,我正在努力解决它(在vc ++ 2008中测试)。

所有代码都可以在以下3个链接中找到:http://www.boost.org/doc/libs/1_46_1/libs/serialization/test/test_primitive.cpp http://www.boost.org/doc/libs/1_46_1/libs/serialization/test/test_tools.hpp和libs / 1_46_1 / libs / serialization / test / text_archive.hpp

请将text_archive.hpp中的标题和typedef更改为多态的,如下所示:

    #include <boost/archive/polymorphic_text_oarchive.hpp>
    typedef boost::archive::polymorphic_text_oarchive test_oarchive;  
    #include <boost/archive/polymorphic_text_iarchive.hpp>  
    typedef boost::archive::polymorphic_text_iarchive test_iarchive;  

使用的预处理程序标志:

BOOST_ALL_DYN_LINK; BOOST_FILESYSTEM_NO_DEPRECATED; BOOST_FILESYSTEM_VERSION = 3

错误讯息:

  

------ Build build:Project:TestSer4,Configuration:Debug Win32 ------
  编译...
  test_primitive.cpp
  c:\ program files \ boost \ boost_1_46_1 \ boost \ archive \ detail \ oserializer.hpp(88):错误   C2664:'void boost :: archive :: polymorphic_oarchive_impl :: save(const bool)':不能

  将参数1从'const A'转换为'const bool'
         没有可用于执行此转换的用户定义转换运算符,
  或者操作员不能被称为          c:\ program files \ boost \ boost_1_46_1 \ boost \ archive \ detail \ oserializer.hpp(232):请参阅函数模板实例化的参考'void   正在编译的boost :: archive :: save_access :: save_primitive(Archive&amp;,const T&amp;)          与
         [
             存档=的boost ::档案:: polymorphic_oarchive,
             T =甲
         ]
         c:\ program files \ boost \ boost_1_46_1 \ boost \ archive \ detail \ oserializer.hpp(308):参见函数模板实例化的参考'void   boost :: archive :: detail :: save_non_pointer_type :: save_primitive :: invoke(Archive&amp;,const T&amp;)'正在编译中
         与
         [
             存档=的boost ::档案:: polymorphic_oarchive,
             T =甲
         ]
         c:\ program files \ boost \ boost_1_46_1 \ boost \ archive \ detail \ oserializer.hpp(525):参见函数模板实例化'void boost :: archive :: detail :: save_non_pointer_type :: invoke(Archive&amp;,const) T&amp;)'正在编制中          与
         [
             存档=的boost ::档案:: polymorphic_oarchive,
             T =甲
         ]
         c:\ program files \ boost \ boost_1_46_1 \ boost \ archive \ polymorphic_oarchive.hpp(122):参见函数模板实例化'void boost :: archive :: save(Archive&amp;,T&amp;)'正在编译
         与
         [
             存档=的boost ::档案:: polymorphic_oarchive,
             T =甲
         ]
         c:\ program files \ boost \ boost_1_46_1 \ boost \ archive \ detail \ interface_oarchive.hpp(63):参见函数模板实例化'void boost :: archive :: polymorphic_oarchive_impl :: save_override(const boost :: serialization :: nvp) &amp;,int)'正在编译中          与
         [
             T =甲
         ]
         c:\ program files \ boost \ boost_1_46_1 \ boost \ archive \ detail \ polymorphic_oarchive_route.hpp(171):参见函数模板实例化'Archive&amp; boost :: archive :: detail :: interface_oarchive :: operator&lt;&lt; (T&amp;)'正在编制中          与
         [
             存档=的boost ::档案:: polymorphic_oarchive,
             T = const boost :: serialization :: nvp
         ]
         c:\ apps \ proj \ serilization \ testser4 \ testser4 \ test_primitive.cpp(73):参见函数模板实例化'boost :: archive :: polymorphic_oarchive&amp; boost :: archive :: detail :: polymorphic_oarchive_route :: operator&lt ;&lt;&gt;(const boost :: serialization :: nvp&amp;)'正在编译中          与
         [
             ArchiveImplementation =的boost ::档案:: text_oarchive_impl,
             T =甲
         ]
  构建日志保存在“file:// C:\ apps \ proj \ Serilization \ BusSchedEx \ BusSchedEx \ Debug \ BuildLog.htm”中
  TestSer4 - 1个错误,0个警告
  ==========构建:0成功,1个失败,0个最新,0个跳过==========

请帮忙。

1 个答案:

答案 0 :(得分:0)

您不能将多态存档与boost::serialization::primitive_type一起使用。有关说明,请参阅this Boost ticket

IMO这是整个boost :: serialization理念中一个真正无法解决的概念性错误。