提升序列化和命名空间

时间:2012-02-15 00:35:50

标签: c++ boost boost-serialization

我是使用Boost序列化的新手。我正在使用xml序列化和非侵入式版本。我一步一步地按照教程(来自Boost网站),我的代码工作正常。

当我把我的类(代码分为.h和.cpp加上main.cpp文件)放在命名空间(ns_mytests)中时会出现问题。在这种情况下,编译器(g ++)抱怨并且我有以下错误:

g++ -c -g test.o.d -o build/Debug/GNU-Linux-x86/sources/test.o sources/test.cpp
/opt/local/include/boost/serialization/split_free.hpp: In static member function 'static void boost::serialization::free_saver<Archive, T>::invoke(Archive&, const T&, unsigned int) [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]':
/opt/local/include/boost/serialization/split_free.hpp:74:   instantiated from 'void boost::serialization::split_free(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]'
sources/test.h:117:   instantiated from 'void boost::serialization::serialize(Archive&, ns_mytests::Test&, unsigned int) [with Archive = boost::archive::xml_oarchive]'
/opt/local/include/boost/serialization/serialization.hpp:128:   instantiated from 'void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]'
/opt/local/include/boost/archive/detail/oserializer.hpp:148:   instantiated from 'void boost::archive::detail::oserializer<Archive, T>::save_object_data(boost::archive::detail::basic_oarchive&, const void*) const [with Archive = boost::archive::xml_oarchive, T = ns_mytests::Test]'
sources/test.cpp:146:   instantiated from here
/opt/local/include/boost/serialization/split_free.hpp:45: error: no matching function for call to 'save(boost::archive::xml_oarchive&, const ns_mytests::Test&, const boost::serialization::version_type&)'
make[2]: *** [build/Debug/GNU-Linux-x86/sources/test.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

我肯定我做错了什么,但我找不到我的错误。

感谢任何帮助。

谢谢, westfork

1 个答案:

答案 0 :(得分:1)

在命名空间中定义非侵入式save,其中定义了要序列化的类型。