2008-09-17 76 views
8

我有一个模板类,我序列化(称为C),为此我想指定升序序列化的版本。由于BOOST_CLASS_VERSION不适用于模板类。我试过这个:Boost序列化:指定一个模板类版本

namespace boost { 
namespace serialization { 
    template< typename T, typename U > 
    struct version< C<T,U> > 
    { 
     typedef mpl::int_<1> type; 
     typedef mpl::integral_c_tag tag; 
     BOOST_STATIC_CONSTANT(unsigned int, value = version::type::value); 
    }; 
} 
} 

但它不能编译。根据VC8,以BOOST_CLASS_VERSION的后续调用给出了这样的错误:

error C2913: explicit specialization; 'boost::serialization::version' is not a specialization of a class template

什么是做了正确的方法是什么?

+0

“但它不编译”。你能给我们一些信息吗? – 2008-09-17 12:39:39

+0

VC8下: 错误C2913:明确的专业化; 'boost :: serialization :: version'不是在随后调用BOOST_CLASS_VERSION时类模板 的专门化。 – Jazz 2008-09-17 13:28:40

回答

11
#include <boost/serialization/version.hpp> 

:-)

1

我能够正确使用宏BOOST_CLASS_VERSION直到我封装它在命名空间里。返回编译错误是:

error C2988: unrecognizable template declaration/definition 
error C2143: syntax error: missing ';' before '<' 
error C2913: explicit specialization; 'Romer::RDS::Settings::boost::serialization::version' is not a specialization of a class template 
error C2059: syntax error: '<' 
error C2143: syntax error: missing ';' before '{' 
error C2447: '{': missing function header (old-style formal list?) 

在之前编辑建议,移动BOOST_CLASS_VERSION全球范围内解决的问题。我宁愿让宏接近引用的结构。