c++
I am trying to test the following sample code which explains how to serialize a user defined primitive type class in boost,it works fine.But if I switch to polymorphic_archive (testing with polymorphic_text_*) which I will have to use in my project, it fails to compile and I am struggling to fix it(testing in vc++2008).
All the code can be found in the below 3 links: 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 and libs/1_46_1/libs/serialization/test/text_archive.hpp
Please change the headers and typedefs in the text_archive.hpp to polymorphic ones as follows to get the error:
#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;
Preprocessor flags used :
BOOST_ALL_DYN_LINK;BOOST_FILESYSTEM_NO_DEPRECATED;BOOST_FILESYSTEM_VERSION=3
Error message:
------ Build started: Project: TestSer4, Configuration: Debug Win32 ------
Compiling...
test_primitive.cpp
c:program filesboostboost_1_46_1boostarchivedetailoserializer.hpp(88) : error C2664: 'void boost::archive::polymorphic_oarchive_impl::save(const bool)' : cannot
convert parameter 1 from 'const A' to 'const bool'
No user-defined-conversion operator available that can perform this conversion,
or the operator cannot be called
c:program filesboostboost_1_46_1boostarchivedetailoserializer.hpp(232) : see reference to function template instantiation 'void boost::archive::save_access::save_primitive(Archive &,const T &)' being compiled
with
[
Archive=boost::archive::polymorphic_oarchive,
T=A
]
c:program filesboostboost_1_46_1boostarchivedetailoserializer.hpp(308) : see reference to function template instantiation 'void boost::archive::detail::save_non_pointer_type::save_primitive::invoke(Archive &,const T &)' being compiled
with
[
Archive=boost::archive::polymorphic_oarchive,
T=A
]
c:program filesboostboost_1_46_1boostarchivedetailoserializer.hpp(525) : see reference to function template instantiation 'void boost::archive::detail::save_non_pointer_type::invoke(Archive &,const T &)' being compiled
with
[
Archive=boost::archive::polymorphic_oarchive,
T=A
]
c:program filesboostboost_1_46_1boostarchivepolymorphic_oarchive.hpp(122) : see reference to function template instantiation 'void boost::archive::save(Archive &,T &)' being compiled
with
[
Archive=boost::archive::polymorphic_oarchive,
T=A
]
c:program filesboostboost_1_46_1boostarchivedetailinterface_oarchive.hpp(63) : see reference to function template instantiation 'void boost::archive::polymorphic_oarchive_impl::save_override(const boost::serialization::nvp &,int)' being compiled
with
[
T=A
]
c:program filesboostboost_1_46_1 boostarchivedetailpolymorphic_oarchive_route.hpp(171) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_oarchive::operator <<(T &)' being compiled
with
[
Archive=boost::archive::polymorphic_oarchive,
T=const boost::serialization::nvp
]
c:appsprojserilizationtestser4testser4test_primitive.cpp(73) : see reference to function template instantiation 'boost::archive::polymorphic_oarchive &boost::archive::detail::polymorphic_oarchive_route::operator <<>(const boost::serialization::nvp &)' being compiled
with
[
ArchiveImplementation=boost::archive::text_oarchive_impl,
T=A
]
Build log was saved at "file://C:appsprojSerilizationBusSchedExBusSchedExDebugBuildLog.htm"
TestSer4 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help.
You cannot use polymorphic archives together with boost::serialization::primitive_type
. See this Boost ticket for an explanation.
IMO this is a real unfixable conceptual bug in the whole boost::serialization idea.
链接地址: http://www.djcxy.com/p/60646.html上一篇: 如何使用boost XML归档序列化OpenCV Mat
下一篇: C ++