Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] Confusion serializing dynamic arraysof pointers.
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-05-04 21:23:38

  "John Murray" <jmurrayufo_at_[hidden]> wrote in message
  Let me begin by saying that I am still rather new to C++ as a language. I've only taken one low level university course on the language, and most of my programs are still very limited in scope and functionality.

  I am attempting to use the serialization library to save and load objects from a dynamic array of pointers. The object to be serialized contains an object***. The first pointer will bring me to an array of 10 elements, from there each element contains an arbitrarily large array of pointers to objects that will be dynamic allocated as they are needed.

  While I understand that the library can handle simple arrays, as well as pointers to objects, I cannot seem to get it work in this instance. Attempting to serialize the pointer itself results in an error.
  **** The current version of the library cannot serialize a pointer to a pointer.

>In static member function 'static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = spell**]':
>instantiated from 'void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = spell**]'
>instantiated from 'void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = spell**]'
>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 = spell**]'
>functions/general.cpp:85: instantiated from here

  This seems to make sense as there is not way for the library to serialize a pointer without knowing what it is pointing to (and array of arrays in this case).

  *** polymorphic objects can be serialzed through a pointer to their base class

  My next choice of action was to try to serialize the pointer just as I had created it during its initialization. My hope was that the library would then be able to reconstruct the object during loading. This is shown in this code.

  < ...>

  *** somethign like the follow ing should work

  class spell_object {

  spell_object spc[10][10];

  ar & spc

  // among other things

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at