开发者

Non-intrusive serialize method for template class

I am using boost serialization, mostly the intrusive version. For a template Matrix class I would like to have the non-intrusive version which works on Visual Studio with the following code:

namespace boost 
{
    namespace serialization 
    {

        template<class Archive, int R, int C, class ElementType>开发者_JAVA技巧
        void serialize(Archive & ar, Matrix<R, C, ElementType> & m, const unsigned int version)
        {
            ar & ...
        }

    } 
}

int R, int C are the row and columns, ElementType is double or float.

However, this does not work on GCC 4.3.2 with the error

error: 'class Matrix<1u, 3u, double>' has no member named 'serialize'

If I use a special form like

namespace boost 
{
    namespace serialization 
    {

        template<class Archive>
        void serialize(Archive & ar, Matrix<3,1,double> & m, const unsigned int version)
        {
            ar & ...
        }

    } 
}

it compiles on GCC, but of course only for a special set of template arguments.

What can I do to make it work on both compilers for all R, C and ElementType?

EDIT: These are the lines causing the error:

/[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>]'


It looks like a signed/unsigned mismatch to me. Your template function is declared with ints but the error indicates that the object which it's trying to match with the template has parameters 1u and 3u. When you instantiate the object that you're trying to serialize, are you using unsigned values for the dimensions? Try changing your serialize template function to take unsigneds or instantiating your Matrix with ints.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜