Boost logo

Boost Users :

Subject: Re: [Boost-users] Serialization of forward declared class
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-01-12 00:37:23


You can't serialize and incomplet type.

Try the following:

class fd; // forward declaration

 class base: class derived
 {
 .....
     fd *ptr;
 .....

     friend class boost::serialization::access;
     template<class Archive>
     void serialize(Archive & ar, const unsigned int file_version);
     {
             (void) file_version;
             ar & ptr;
             ar & boost::serialization::base_object<derived>(*this);

     }

 }; //end of class base

In a *.cpp file

#include "fd.h"

template<class Archive>
void base::serialize(Archive & ar, const unsigned int file_version);
{
    ar & ptr;
    ar & boost::serialization::base_object<derived>(*this);
}

Robert Ramey

"niranjan bangera" <niranjannina_at_[hidden]> wrote in message news:50a2f6f20901112119p631960d5ncc524bec7beef22_at_mail.gmail.com...

  hi all,

     

    i have done in the following way.. even am getting some errors, did i miss any of the headers, or added extra(added extra for sure).

    Any suggestions will be accepted

        #include <boost/serialization/utility.hpp>
        #include <boost/serialization/collection_traits.hpp>
        #include <boost/serialization/serialization.hpp>
        #include <boost/serialization/base_object.hpp>
        #include <fstream>
         #include <boost/archive/text_iarchive.hpp>
        #include <boost/archive/text_oarchive.hpp>
        #include <boost/serialization/assume_abstract.hpp>

      class fd;

     class base: class derived
     {
     .....
         fd *ptr;
     .....

         friend class boost::serialization::access;
         template<class Archive>
         void serialize(Archive & ar, const unsigned int file_version)
         {
                 (void) file_version;
                 ar & ptr;
                 ar & boost::serialization::base_object<derived>(*this);

         }

     }; //end of class base

    Version::1.36.0
    compliler: g++ 4.1.1....

    i am getting a error :
    error: forward declaration of 'struct fd'
    /boost_1_36_0/include/boost-1_36/boost/serialization/access.hpp:109: error: inva
    lid use of undefined type 'struct

    /project/wipro_virtutech_nobackup/users/niranjan/project_new/boost_1_36_0/include/boost-1_36/boost/serialization/extended_type_info_typeid.hpp:117: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.

    Thanks in advance.....

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

  _______________________________________________
  Boost-users mailing list
  Boost-users_at_[hidden]
  http://lists.boost.org/mailman/listinfo.cgi/boost-users



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