2

我正在使用 boost 序列化,主要是侵入式版本。对于模板 Matrix 类,我希望拥有可在 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是行和列,ElementTypedoublefloat.

但是,这不适用于 GCC 4.3.2 并出现错误

error: '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 上编译,但当然只针对一组特殊的模板参数。

我该怎么做才能使它在所有编译器上都工作RC并且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>]'
4

1 回答 1

1

对我来说,这看起来像是有符号/无符号不匹配。您的模板函数是用ints 声明的,但错误表明它试图与模板匹配的对象具有参数1u3u. 当您实例化您尝试序列化的对象时,您是否对维度使用无符号值?尝试将您的序列化模板函数更改为采用unsigneds 或使用 s 实例化您的矩阵int

于 2011-03-31T01:06:59.970 回答