Boost logo

Boost Users :

From: Joseph Turian (turian_at_[hidden])
Date: 2006-01-17 14:47:06


Hi Robert and everyone,

Thank you for explaining to me about BOOST_STRONGTYPE. I'll let you
know how that goes for me. And thank you for being so patient and
trying to help me get serialization working in my program.

In the meantime, I'm experiencing a much simpler problem. Although I
can serialize classes of the form boost::shared_ptr<T>, where T is a
class I've defined, I get compilation errors if I try to serialize a
boost::shared_ptr<int>.

How can I resolve this?

Code snippet:
-----------------------------------------------
#include <iostream>
#include <fstream>

#include <boost/shared_ptr.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/shared_ptr.hpp>

int main() {
        std::ofstream ofs("archive");
        boost::archive::text_oarchive oa(ofs);

        boost::shared_ptr<int> i;
        oa << i;

        return 0;
}
-----------------------------------------------
g++ output:

/usr/include/boost/serialization/shared_ptr.hpp: In function `void
   boost::serialization::serialize(Archive&, boost::shared_ptr<U>&, unsigned
   int) [with Archive = boost::archive::text_oarchive, T = int]':
/usr/include/boost/serialization/serialization.hpp:140: instantiated
from `void boost::serialization::serialize_adl(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T =
boost::shared_ptr<int>]'
/usr/include/boost/archive/detail/oserializer.hpp:147: 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 =
boost::shared_ptr<int>]'
/usr/include/boost/mpl/if.hpp:67: instantiated from here
/usr/include/boost/serialization/shared_ptr.hpp:227: error: incomplete type `
   boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
/usr/include/boost/serialization/shared_ptr.hpp: In function `void
   boost::serialization::save(Archive&, const boost::shared_ptr<U>&, unsigned
   int) [with Archive = boost::archive::text_oarchive, T = int]':
/usr/include/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 = boost::shared_ptr<int>]'
/usr/include/boost/serialization/split_free.hpp:74: instantiated
from `void boost::serialization::split_free(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T =
boost::shared_ptr<int>]'
/usr/include/boost/serialization/shared_ptr.hpp:231: instantiated
from `void boost::serialization::serialize(Archive&,
boost::shared_ptr<U>&, unsigned int) [with Archive =
boost::archive::text_oarchive, T = int]'
/usr/include/boost/serialization/serialization.hpp:140: instantiated
from `void boost::serialization::serialize_adl(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T =
boost::shared_ptr<int>]'
/usr/include/boost/archive/detail/oserializer.hpp:147: 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 =
boost::shared_ptr<int>]'
/usr/include/boost/mpl/if.hpp:67: instantiated from here
/usr/include/boost/serialization/shared_ptr.hpp:183: error: incomplete type `
   boost::STATIC_ASSERTION_FAILURE<false>' does not have member `value'
/usr/include/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 = int]':
/usr/include/boost/serialization/serialization.hpp:81: instantiated
from `void boost::serialization::serialize(Archive&, T&, unsigned int)
[with Archive = boost::archive::text_oarchive, T = int]'
/usr/include/boost/serialization/serialization.hpp:140: instantiated
from `void boost::serialization::serialize_adl(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T = int]'
/usr/include/boost/archive/detail/oserializer.hpp:232: instantiated
from `boost::archive::detail::pointer_oserializer<T,
Archive>::pointer_oserializer() [with T = int, Archive =
boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/oserializer.hpp:197: instantiated
from `const boost::archive::detail::pointer_oserializer<int,
boost::archive::text_oarchive>
boost::archive::detail::pointer_oserializer<int,
boost::archive::text_oarchive>::instance'
/usr/include/boost/archive/detail/oserializer.hpp:189: instantiated
from `static const boost::archive::detail::pointer_oserializer<T,
Archive>& boost::archive::detail::pointer_oserializer<T,
Archive>::instantiate() [with T = int, Archive =
boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/oserializer.hpp:514: instantiated
from `const boost::archive::detail::basic_pointer_oserializer&
boost::archive::detail::instantiate_pointer_oserializer(Archive*, T*)
[with Archive = boost::archive::text_oarchive, T = int]'
/usr/include/boost/archive/detail/interface_oarchive.hpp:65:
instantiated from `const
boost::archive::detail::basic_pointer_oserializer*
boost::archive::detail::interface_oarchive<Archive>::register_type(const
T*) [with T = int, Archive = boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/oserializer.hpp:343: instantiated
from `static const boost::archive::detail::basic_pointer_oserializer*
boost::archive::detail::save_pointer_type<Archive,
TPtr>::non_abstract<T>::register_type(Archive&) [with T = const int,
Archive = boost::archive::text_oarchive, TPtr = const int*]'
/usr/include/boost/archive/detail/oserializer.hpp:359: instantiated
from `static const boost::archive::detail::basic_pointer_oserializer*
boost::archive::detail::save_pointer_type<Archive,
TPtr>::register_type(Archive&, T&) [with T = const int, Archive =
boost::archive::text_oarchive, TPtr = const int*]'
/usr/include/boost/archive/detail/oserializer.hpp:459: instantiated
from `static void boost::archive::detail::save_pointer_type<Archive,
TPtr>::invoke(Archive&, TPtr) [with Archive =
boost::archive::text_oarchive, TPtr = const int*]'
/usr/include/boost/archive/detail/oserializer.hpp:535: instantiated
from `void boost::archive::save(Archive&, const T&) [with Archive =
boost::archive::text_oarchive, T = const int*]'
/usr/include/boost/archive/basic_text_oarchive.hpp:78: instantiated
from `void boost::archive::basic_text_oarchive<Archive>::save_override(T&,
int) [with T = const int* const, Archive =
boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/interface_oarchive.hpp:85:
instantiated from `Archive&
boost::archive::detail::interface_oarchive<Archive>::operator<<(T&)
[with T = const int* const, Archive = boost::archive::text_oarchive]'
/usr/include/boost/serialization/nvp.hpp:77: instantiated from `void
boost::serialization::nvp<T>::save(Archivex&, unsigned int) const
[with Archivex = boost::archive::text_oarchive, T = const int*]'
/usr/include/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<const int*>]'
/usr/include/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<const
int*>]'
/usr/include/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<const int*>]'
/usr/include/boost/serialization/nvp.hpp:87: instantiated from `void
boost::serialization::nvp<T>::serialize(Archive&, unsigned int) [with
Archive = boost::archive::text_oarchive, T = const int*]'
/usr/include/boost/serialization/access.hpp:109: instantiated from
`static void boost::serialization::access::serialize(Archive&, T&,
unsigned int) [with Archive = boost::archive::text_oarchive, T =
boost::serialization::nvp<const int*>]'
/usr/include/boost/serialization/serialization.hpp:81: instantiated
from `void boost::serialization::serialize(Archive&, T&, unsigned int)
[with Archive = boost::archive::text_oarchive, T =
boost::serialization::nvp<const int*>]'
/usr/include/boost/serialization/serialization.hpp:140: instantiated
from `void boost::serialization::serialize_adl(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T =
boost::serialization::nvp<const int*>]'
/usr/include/boost/archive/detail/oserializer.hpp:252: instantiated
from `static void
boost::archive::detail::save_non_pointer_type<Archive,
T>::save_only::invoke(Archive&, const T&) [with Archive =
boost::archive::text_oarchive, T = boost::serialization::nvp<const
int*>]'
/usr/include/boost/archive/detail/oserializer.hpp:321: instantiated
from `static void
boost::archive::detail::save_non_pointer_type<Archive,
T>::invoke(Archive&, const T&) [with Archive =
boost::archive::text_oarchive, T = boost::serialization::nvp<const
int*>]'
/usr/include/boost/archive/detail/oserializer.hpp:535: instantiated
from `void boost::archive::save(Archive&, const T&) [with Archive =
boost::archive::text_oarchive, T = boost::serialization::nvp<const
int*>]'
/usr/include/boost/archive/basic_text_oarchive.hpp:78: instantiated
from `void boost::archive::basic_text_oarchive<Archive>::save_override(T&,
int) [with T = const boost::serialization::nvp<const int*>, Archive =
boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/interface_oarchive.hpp:85:
instantiated from `Archive&
boost::archive::detail::interface_oarchive<Archive>::operator<<(T&)
[with T = const boost::serialization::nvp<const int*>, Archive =
boost::archive::text_oarchive]'
/usr/include/boost/serialization/shared_ptr.hpp:185: instantiated
from `void boost::serialization::save(Archive&, const
boost::shared_ptr<U>&, unsigned int) [with Archive =
boost::archive::text_oarchive, T = int]'
/usr/include/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 = boost::shared_ptr<int>]'
/usr/include/boost/serialization/split_free.hpp:74: instantiated
from `void boost::serialization::split_free(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T =
boost::shared_ptr<int>]'
/usr/include/boost/serialization/shared_ptr.hpp:231: instantiated
from `void boost::serialization::serialize(Archive&,
boost::shared_ptr<U>&, unsigned int) [with Archive =
boost::archive::text_oarchive, T = int]'
/usr/include/boost/serialization/serialization.hpp:140: instantiated
from `void boost::serialization::serialize_adl(Archive&, T&, unsigned
int) [with Archive = boost::archive::text_oarchive, T =
boost::shared_ptr<int>]'
/usr/include/boost/archive/detail/oserializer.hpp:147: 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 =
boost::shared_ptr<int>]'
/usr/include/boost/mpl/if.hpp:67: instantiated from here
/usr/include/boost/serialization/access.hpp:109: error: request for member `
   serialize' in `t', which is of non-aggregate type `int'

-----------------------------------------------

Thanks again for being so helpful!

   Joseph

--
http://www.cs.nyu.edu/~turian/

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