私は最近、オブジェクトのベクトルを含むクラスをシリアライズしたいと考えていました。#include <boost/serialization/vector.hpp> を含めると、単純な & 演算子でそれを実行できるというドキュメントを読みました。残念ながら、コンパイラはシリアル化コードのビルドに同意しますが、逆シリアル化テストケースをコンパイルすることはできません。何が間違っているのでしょうか?
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <fstream>
class A
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) const
{
}
};
class B
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) const
{
ar & a;
}
std::vector<A> a;
};
int main()
{
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
B b;
ia >> b;
}
以下は、コンパイラのエラーです。
> make testcase
g++ -ggdb -fpermissive testcase.cpp -o testcase
In file included from /usr/include/boost/archive/detail/oserializer.hpp:67:0,
from /usr/include/boost/archive/detail/interface_oarchive.hpp:23,
from /usr/include/boost/archive/detail/common_oarchive.hpp:22,
from /usr/include/boost/archive/basic_text_oarchive.hpp:32,
from /usr/include/boost/archive/text_oarchive.hpp:31,
from testcase.cpp:1:
/usr/include/boost/archive/detail/check.hpp: In instantiation of ‘void boost::archive::detail::check_const_loading() [with T = const std::vector<A>]’:
/usr/include/boost/archive/detail/iserializer.hpp:577:5: required from ‘void boost::archive::load(Archive&, T&) [with Archive = boost::archive::text_iarchive; T = const std::vector<A>]’
/usr/include/boost/archive/detail/common_iarchive.hpp:66:9: required from ‘void boost::archive::detail::common_iarchive<Archive>::load_override(T&, int) [with T = const std::vector<A>; Archive = boost::archive::text_iarchive]’
/usr/include/boost/archive/basic_text_iarchive.hpp:65:9: required from ‘void boost::archive::basic_text_iarchive<Archive>::load_override(T&, int) [with T = const std::vector<A>; Archive = boost::archive::text_iarchive]’
/usr/include/boost/archive/text_iarchive.hpp:82:9: required from ‘void boost::archive::text_iarchive_impl<Archive>::load_override(T&, int) [with T = const std::vector<A>; Archive = boost::archive::text_iarchive]’
/usr/include/boost/archive/detail/interface_iarchive.hpp:60:9: required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = const std::vector<A>; Archive = boost::archive::text_iarchive]’
/usr/include/boost/archive/detail/interface_iarchive.hpp:67:35: [ skipping 9 instantiation contexts ]
/usr/include/boost/archive/detail/iserializer.hpp:592:5: required from ‘void boost::archive::load(Archive&, T&) [with Archive = boost::archive::text_iarchive; T = B]’
/usr/include/boost/archive/detail/common_iarchive.hpp:66:9: required from ‘void boost::archive::detail::common_iarchive<Archive>::load_override(T&, int) [with T = B; Archive = boost::archive::text_iarchive]’
/usr/include/boost/archive/basic_text_iarchive.hpp:65:9: required from ‘void boost::archive::basic_text_iarchive<Archive>::load_override(T&, int) [with T = B; Archive = boost::archive::text_iarchive]’
/usr/include/boost/archive/text_iarchive.hpp:82:9: required from ‘void boost::archive::text_iarchive_impl<Archive>::load_override(T&, int) [with T = B; Archive = boost::archive::text_iarchive]’
/usr/include/boost/archive/detail/interface_iarchive.hpp:60:9: required from ‘Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = B; Archive = boost::archive::text_iarchive]’
testcase.cpp:35:8: required from here
/usr/include/boost/archive/detail/check.hpp:162:1: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’