基本的にサブクラスを構築する「ジェネレーター」クラスがあります。このことを使用するには、単純にサブクラス化し、正しいパラメーターを渡して、構築したいオブジェクトを構築します。これらをシリアル化したいのですが、すべてのデータがベースにあるため、サブクラスごとにシリアル化する正当な理由はありません。これが私が例として持っているものです:
#include <boost/serialization/serialization.hpp>
template < typename T >
struct test_base
{
// works...
//template < typename Archive >
//void serialize(Archive &, unsigned int const)
// {
//}
};
template < typename T >
void f(test_base<T> const&) {}
struct test_derived : test_base<int>
{
};
namespace boost { namespace serialization {
template < typename Archive, typename T >
void serialize(Archive &, test_base<T> &, unsigned int const)
{
}
}}
#include <boost/archive/binary_oarchive.hpp>
#include <sstream>
int main()
{
int x = 5;
test_derived d;
//boost::serialization::serialize(x, d, 54); // <- works.
std::ostringstream str;
boost::archive::binary_oarchive out(str);
out & d; // no worky.
}
できれば無料版で動いてほしい。それは...ですか?
上記のバージョンは、serialize が test_derived のメンバーではないというエラーを吐き出します。