Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] Can't Serialize vectors of user-defined classes
From: Moch Ramis (mocramis_at_[hidden])
Date: 2010-07-14 03:55:25

hi all.

I recently tried to execute this very simple example:

#include <iostream>

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <fstream>

class A

  //Serialization tasks
  friend class boost::serialization::access;
  template<class Archive>
  void serialize(Archive & , const unsigned int )

int main()
   std::vector<A> eig;
   std::cout <<eig.size()<<std::endl;
  std::ofstream of("file.txt");
    boost::archive::text_oarchive oa(of);
    oa << eig;
  std::ifstream ifs("file.txt");
    boost::archive::text_iarchive ia(ifs);
    ia >> eig;
  std::cout <<eig.size()<<std::endl;

   return 0;

On my compiler (gcc 4.4.1), it compile fine but there is a runtime
error when the application start:

/.../boost/serialization/singleton.hpp:124: static T&
boost::serialization::singleton<T>::get_instance() [with T =
std::vector<EigMemberProps<int, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
std::allocator<EigMemberProps<int, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > > > >]: Assertion `!
detail::singleton_wrapper<T>::m_is_destroyed' failed.

Curiously, the comportment of the gcc 4.1.2 of codepad is not the

Curiously, this works fine on my compiler when i olny serialize A but
not with the codepad compiler:

Do you have any clue about this problem ?


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