Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] Serializing a vector of pointers
From: Dante Stroe (dante.stroe_at_[hidden])
Date: 2010-07-02 09:30:54


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<boost/archive/tmpdir.hpp>
#include<boost/archive/text_iarchive.hpp>
#include<boost/archive/text_oarchive.hpp>
#include<boost/serialization/vector.hpp>
#include<boost/serialization/utility.hpp>

class test
{
     friend class boost::serialization::access;
     std::vector<double*> r; // = std::vector<double*>(n);
     template<class Archive>
     void serialize(Archive& ar, const unsigned int /*file_version*/){
         ar& r;
     }
public:
     test(){};
};

void save_test(const test&s, const char * filename){
     // make an archive
     std::ofstream ofs(filename);
     boost::archive::text_oarchive oa(ofs);
     oa<< s;
}

void restore_test(test&s, const char * filename)
{
     // open the archive
     std::ifstream ifs(filename);
     boost::archive::text_iarchive ia(ifs);
     // restore the schedule from the archive
     ia>> s;
}

int main()
{
     return 0;
}

Compilation errors:

/home/dante/pagmo/examples/demo_serialization.cpp: In instantiation of
‘void test::serialize(Archive&, unsigned int) [with Archive =
boost::archive::text_iarchive]’:
/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_iarchive, T = test]’
/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 = test]’
/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 = test]’
/home/dante/pagmo/external_headers/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::text_iarchive, T =
test]’
/home/dante/pagmo/examples/demo_serialization.cpp:48: instantiated from here
/home/dante/pagmo/examples/demo_serialization.cpp:20: warning: unused
parameter ‘file_version’
/home/dante/pagmo/examples/demo_serialization.cpp: In instantiation of
‘void test::serialize(Archive&, unsigned int) [with Archive =
boost::archive::text_oarchive]’:
/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 = test]’
/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 = test]’
/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 = test]’
/home/dante/pagmo/external_headers/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::text_oarchive, T = test]’
/home/dante/pagmo/examples/demo_serialization.cpp:48: instantiated from here
/home/dante/pagmo/examples/demo_serialization.cpp:20: warning: unused
parameter ‘file_version’
In file included from
/home/dante/pagmo/external_headers/boost/serialization/static_warning.hpp:73,
from
/home/dante/pagmo/external_headers/boost/serialization/extended_type_info_typeid.hpp:27,
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/mpl/print.hpp: In instantiation
of
‘boost::mpl::print<boost::serialization::BOOST_SERIALIZATION_STATIC_WARNING_LINE<148>
>’:
/home/dante/pagmo/external_headers/boost/serialization/static_warning.hpp:92:
instantiated from ‘boost::serialization::static_warning_test<false, 148>’
/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<double* const>]’
/home/dante/pagmo/external_headers/boost/serialization/split_member.hpp:43:
instantiated from ‘static void
boost::serialization::detail::member_saver<Archive, T>::invoke(Archive&,
const T&, unsigned int) [with Archive = boost::archive::text_oarchive, T
= boost::serialization::nvp<double* const>]’
/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<double* const>]’
/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<double* const>]’
/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<double* const>]’
/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<double* const>]’
/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<double* const>, 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<double* const>, 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<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 = const boost::serialization::nvp<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 = const boost::serialization::nvp<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 = const boost::serialization::nvp<double* const>, 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<double*, std::allocator<double*> >]’
/home/dante/pagmo/external_headers/boost/serialization/vector.hpp:53:
instantiated from ‘void boost::serialization::save(Archive&, const
std::vector<U, Allocator>&, unsigned int, mpl_::false_) [with Archive =
boost::archive::text_oarchive, U = double*, Allocator =
std::allocator<double*>]’
/home/dante/pagmo/external_headers/boost/serialization/vector.hpp:120:
instantiated from ‘void boost::serialization::save(Archive&, const
std::vector<U, Allocator>&, unsigned int) [with Archive =
boost::archive::text_oarchive, U = double*, Allocator =
std::allocator<double*>]’
/home/dante/pagmo/external_headers/boost/serialization/split_free.hpp:45: instantiated
from ‘static void boost::serialization::free_saver<Archive,
T>::invoke(Archive&, const T&, unsigned int) [with Archive =
boost::archive::text_oarchive, T = std::vector<double*,
std::allocator<double*> >]’
/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<double*,
std::allocator<double*> >]’
/home/dante/pagmo/external_headers/boost/serialization/vector.hpp:151:
instantiated from ‘void boost::serialization::serialize(Archive&,
std::vector<U, Allocator>&, unsigned int) [with Archive =
boost::archive::text_oarchive, U = double*, Allocator =
std::allocator<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 =
std::vector<double*, std::allocator<double*> >]’
/home/dante/pagmo/external_headers/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::text_oarchive, T =
std::vector<double*, std::allocator<double*> >]’
/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<Archive,
T>::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<Archive,
T>::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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net