1

I'm new using Boost serialization. I'm using xml serialization and the non intrusive version. I followed the tutorial (from Boost website) step by step and my code works fine.

The problem arise when I put my class (the code is divided in .h and .cpp plus a main.cpp file) in a namespace (ns_mytests). In this case the compiler (g++) complains and I have the following errors:

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

It's sure that I'm doing wrong something, but I could't find my error.

Any help is appreciated.

Thanks, westfork

2
  • 1
    It says quite clearly that it's trying to invoke a function with the signature save(boost::archive::xml_oarchive&, ns_mytests::Test const&, boost::serialization::version_type const&) -- do you have such a function? If you do, what namespace is it in? (Hint, hint, show your code, not just your errors.)
    – ildjarn
    Feb 15, 2012 at 0:38
  • Thank you. Yes it was a problem with namespaces.
    – westfork
    May 12, 2012 at 17:33

1 Answer 1

1

Define the non-intrusive save in the namespace where the type to be serialized is defined.

1
  • You are welcome. Please feel free to mark the answer properly if it was of any help. May 13, 2012 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.