I have a class and I'm trying to serialize shared_ptr, but the normal object serialization method does not work:
class Object {
public:
Object();
~Object();
shared_ptr<char>objectone;
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & objectone;
}
};
I even tried to do it this way, but it still doesn't work:
void serialize(Archive &ar, const unsigned int version)
{
for (int i = 0; i < (strlen(objectone.get())); i++)
ar & objectone.get()[i];
}
Any ideas how to approach this? Thank.
Additional Information:
I have already included both shared_ptr header files:
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/shared_ptr_132.hpp>
I tried converting to a string and serializing it this way, but it causes the following error: raising :: archive :: archive_exception "what (): stream error
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, const unsigned int version)
{
if (objectone.get()) {
string temp(objectone.get());
ar & temp;
}
ar & objectone;
}
source
share