我有一个来自外部库的结构,我为此编写了一些非侵入式序列化方法。还有这个结构的包装器,我试图将所有依赖关系从外部结构保留到这个包装器。问题是,所有的序列化方法都是模板,所以它们是在头文件中定义的,并将依赖关系从外部库传播到每个序列化包装器的人,这是我试图避免的。有可能解决这个问题吗?
UPD:最初我有这样的事情:
// serialization.h
#include <external_library.h>
template <typename Archive>
void serialize(Archive& archive, ExternalStruct& external_struct, const unsigned int version) {
// ...
}
然后我尝试使特定类型的存档的序列化函数非模板:
// serialization.h
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
struct ExternalStruct;
void serialize(boost::archive::binary_iarchive& archive, ExternalStruct& external_struct, const unsigned int version);
void serialize(boost::archive::binary_oarchive& archive, ExternalStruct& external_struct, const unsigned int version);
// serialization.cpp
#include <external_library.h>
#include "serialization.h"
void serialize(boost::archive::binary_iarchive& archive, ExternalStruct& external_struct, const unsigned int version) {
// ...
}
void serialize(boost::archive::binary_oarchive& archive, ExternalStruct& external_struct, const unsigned int version) {
// ...
}
但是后来我得到了很多编译错误:
no type named 'type' in 'struct boost::mpl::greater<boost::serialization::tracking_level<ExternalStruct>, mpl_::int_<0> >'
BOOST_STATIC_WARNING(typex::value);