我正在使用boost序列化,主要是侵入版本。对于模板Matrix类,我希望non-intrusive version能够在Visual Studio上使用以下代码:
namespace boost
{
namespace serialization
{
template<class Archive, int R, int C, class ElementType>
void serialize(Archive & ar, Matrix<R, C, ElementType> & m, const unsigned int version)
{
ar & ...
}
}
}
int R
,int C
是行和列,ElementType
是double
或float
。
但是,这不适用于带有错误
的GCC 4.3.2error: 'class Matrix<1u, 3u, double>' has no member named 'serialize'
如果我使用像
这样的特殊表格namespace boost
{
namespace serialization
{
template<class Archive>
void serialize(Archive & ar, Matrix<3,1,double> & m, const unsigned int version)
{
ar & ...
}
}
}
它在GCC上编译,但当然只针对一组特殊的模板参数。
我可以做些什么来使其适用于所有R
,C
和ElementType
的两个编译器?
编辑:这些是导致错误的行:
/[myfolder]/lib/BOOST/1_44_0/include/boost/serialization/access.hpp: In static member function 'static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = Matrix<3u, 1u, double>]':
/[myfolder]/lib/BOOST/1_44_0/include/boost/serialization/serialization.hpp:70: instantiated from 'void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = Matrix<3u, 1u, double>]'
/[myfolder]/lib/BOOST/1_44_0/include/boost/serialization/serialization.hpp:129: instantiated from 'void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::binary_iarchive, T = Matrix<3u, 1u, double>]'
/[myfolder]/lib/BOOST/1_44_0/include/boost/archive/detail/iserializer.hpp:182: instantiated from 'void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::binary_iarchive, T = Matrix<3u, 1u, double>]'
答案 0 :(得分:1)
它看起来像是签名/未签名的不匹配给我。您的模板函数使用int
声明,但错误表示它尝试与模板匹配的对象具有参数1u
和3u
。当您实例化您尝试序列化的对象时,您是否使用维度的无符号值?尝试更改序列化模板函数以使用unsigned
或使用int
实例化Matrix。