Re: [Boost-users] Serialization of forward declared class

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
#include #include #include #include <fstream> #include #include #include 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.....

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"
participants (2)
-
niranjan bangera
-
Robert Ramey