[Serialization] Serializing a vector of pointers
Hello,
I am trying to serialize a vector of pointers (Below you have a piece of
dummy code that reproduces the error) but I get compilation errors. As I
understood from the tutorial this should pretty much work out of the
box. Am I missing something? I am using gcc 4.1 and the 1.43 version of
the boost library.
Thanks a lot,
Dante
Test program:
#include<cstddef>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<vector>
#include
’: /home/dante/pagmo/external_headers/boost/serialization/static_warning.hpp:92: instantiated from ‘boost::serialization::static_warning_test
’ /home/dante/pagmo/external_headers/boost/archive/detail/check.hpp:148: instantiated from ‘void boost::archive::detail::check_pointer_tracking() [with T = double]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:454: instantiated from ‘static void boost::archive::detail::save_pointer_type<Archive>::save(Archive&, const T&) [with T = double, Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:473: instantiated from ‘static void boost::archive::detail::save_pointer_type<Archive>::invoke(Archive&, TPtr) [with TPtr = double*, Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:525: instantiated from ‘void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = double* const]’ /home/dante/pagmo/external_headers/boost/archive/detail/common_oarchive.hpp:69: instantiated from ‘void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = double* const, Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/basic_text_oarchive.hpp:80: instantiated from ‘void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = double* const, Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/detail/interface_oarchive.hpp:63: instantiated from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = double* const, Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/serialization/nvp.hpp:79: instantiated from ‘void boost::serialization::nvp<T>::save(Archivex&, unsigned int) const [with Archivex = boost::archive::text_oarchive, T = double* const]’ /home/dante/pagmo/external_headers/boost/serialization/access.hpp:93: instantiated from ‘static void boost::serialization::access::member_save(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = const boost::serialization::nvp ]’ /home/dante/pagmo/external_headers/boost/serialization/split_member.hpp:43: instantiated from ‘static void boost::serialization::detail::member_saver ::invoke(Archive&, const T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = boost::serialization::nvp ]’ /home/dante/pagmo/external_headers/boost/serialization/split_member.hpp:69: instantiated from ‘void boost::serialization::split_member(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = boost::serialization::nvp ]’ /home/dante/pagmo/external_headers/boost/serialization/nvp.hpp:89: instantiated from ‘void boost::serialization::nvp<T>::serialize(Archive&, unsigned int) [with Archive = boost::archive::text_oarchive, T = double* const]’ /home/dante/pagmo/external_headers/boost/serialization/access.hpp:118: instantiated from ‘static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = boost::serialization::nvp ]’ /home/dante/pagmo/external_headers/boost/serialization/serialization.hpp:74: instantiated from ‘void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = boost::serialization::nvp ]’ /home/dante/pagmo/external_headers/boost/serialization/serialization.hpp:133: instantiated from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = boost::serialization::nvp ]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:241: instantiated from ‘static void boost::archive::detail::save_non_pointer_type<Archive>::save_only::invoke(Archive&, const T&) [with T = boost::serialization::nvp , Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:308: instantiated from ‘static void boost::archive::detail::save_non_pointer_type<Archive>::invoke(Archive&, const T&) [with T = boost::serialization::nvp , Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:525: instantiated from ‘void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = const boost::serialization::nvp ]’ /home/dante/pagmo/external_headers/boost/archive/detail/common_oarchive.hpp:69: instantiated from ‘void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = const boost::serialization::nvp , Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/basic_text_oarchive.hpp:80: instantiated from ‘void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = const boost::serialization::nvp , Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/archive/detail/interface_oarchive.hpp:63: instantiated from ‘Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = const boost::serialization::nvp , Archive = boost::archive::text_oarchive]’ /home/dante/pagmo/external_headers/boost/serialization/collections_save_imp.hpp:60: instantiated from ‘void boost::serialization::stl::save_collection(Archive&, const Container&) [with Archive = boost::archive::text_oarchive, Container = std::vector >]’ /home/dante/pagmo/external_headers/boost/serialization/vector.hpp:53: instantiated from ‘void boost::serialization::save(Archive&, const std::vector&, unsigned int, mpl_::false_) [with Archive = boost::archive::text_oarchive, U = double*, Allocator = std::allocator ]’ /home/dante/pagmo/external_headers/boost/serialization/vector.hpp:120: instantiated from ‘void boost::serialization::save(Archive&, const std::vector&, unsigned int) [with Archive = boost::archive::text_oarchive, U = double*, Allocator = std::allocator ]’ /home/dante/pagmo/external_headers/boost/serialization/split_free.hpp:45: instantiated from ‘static void boost::serialization::free_saver ::invoke(Archive&, const T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = std::vector >]’ /home/dante/pagmo/external_headers/boost/serialization/split_free.hpp:74: instantiated from ‘void boost::serialization::split_free(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = std::vector >]’ /home/dante/pagmo/external_headers/boost/serialization/vector.hpp:151: instantiated from ‘void boost::serialization::serialize(Archive&, std::vector&, unsigned int) [with Archive = boost::archive::text_oarchive, U = double*, Allocator = std::allocator ]’ /home/dante/pagmo/external_headers/boost/serialization/serialization.hpp:133: instantiated from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = std::vector >]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:148: instantiated from ‘void boost::archive::detail::oserializer ::save_object_data(boost::archive::detail::basic_oarchive&, const void*) const [with Archive = boost::archive::text_oarchive, T = std::vector >]’ /home/dante/pagmo/examples/demo_serialization.cpp:48: instantiated from here /home/dante/pagmo/external_headers/boost/mpl/print.hpp:55: warning: comparison between signed and unsigned integer expressions In file included from /home/dante/pagmo/external_headers/boost/serialization/extended_type_info_typeid.hpp:36, from /home/dante/pagmo/external_headers/boost/archive/detail/iserializer.hpp:47, from /home/dante/pagmo/external_headers/boost/archive/detail/interface_iarchive.hpp:22, from /home/dante/pagmo/external_headers/boost/archive/detail/common_iarchive.hpp:23, from /home/dante/pagmo/external_headers/boost/archive/basic_text_iarchive.hpp:31, from /home/dante/pagmo/external_headers/boost/archive/text_iarchive.hpp:24, from /home/dante/pagmo/examples/demo_serialization.cpp:10: /home/dante/pagmo/external_headers/boost/serialization/access.hpp: In static member function ‘static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = double]’: /home/dante/pagmo/external_headers/boost/serialization/serialization.hpp:74: instantiated from ‘void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = double]’ /home/dante/pagmo/external_headers/boost/serialization/serialization.hpp:133: instantiated from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = double]’ /home/dante/pagmo/external_headers/boost/archive/detail/iserializer.hpp:182: instantiated from ‘void boost::archive::detail::iserializer ::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::text_iarchive, T = double]’ /home/dante/pagmo/examples/demo_serialization.cpp:48: instantiated from here /home/dante/pagmo/external_headers/boost/serialization/access.hpp:118: error: request for member ‘serialize’ in ‘t’, which is of non-class type ‘double’ /home/dante/pagmo/external_headers/boost/serialization/access.hpp: In static member function ‘static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = double]’: /home/dante/pagmo/external_headers/boost/serialization/serialization.hpp:74: instantiated from ‘void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = double]’ /home/dante/pagmo/external_headers/boost/serialization/serialization.hpp:133: instantiated from ‘void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_oarchive, T = double]’ /home/dante/pagmo/external_headers/boost/archive/detail/oserializer.hpp:148: instantiated from ‘void boost::archive::detail::oserializer ::save_object_data(boost::archive::detail::basic_oarchive&, const void*) const [with Archive = boost::archive::text_oarchive, T = double]’ /home/dante/pagmo/examples/demo_serialization.cpp:48: instantiated from here /home/dante/pagmo/external_headers/boost/serialization/access.hpp:118: error: request for member ‘serialize’ in ‘t’, which is of non-class type ‘double’ make[2]: *** [examples/CMakeFiles/demo_serialization.dir/demo_serialization.o] Error 1 make[1]: *** [examples/CMakeFiles/demo_serialization.dir/all] Error 2 make: *** [all] Error 2
Dante Stroe wrote:
Hello,
I am trying to serialize a vector of pointers (Below you have a piece of dummy code that reproduces the error) but I get compilation errors. As I understood from the tutorial this should pretty much work out of the box. Am I missing something? I am using gcc 4.1 and the 1.43 version of the boost library.
Thanks a lot, Dante
Test program:
#include<cstddef> #include<iomanip> #include<iostream> #include<fstream> #include<vector> #include
#include #include #include #include class test { friend class boost::serialization::access; std::vector
r; // = std::vector (n); template<class Archive> void serialize(Archive& ar, const unsigned int /*file_version*/){ ar& r; } public: test(){}; };
I'm guessing that there is a problem serializing a pointer to a double which is a primitive. This is inhibited as it tends to have undesired side effects. You might try a strong type or serialization of a class which contains nothing but a double. Robert Ramey
participants (2)
-
Dante Stroe
-
Robert Ramey