I have a class and I am trying to serialize a shared_ptr but the normal method of serializing an object is not working:
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've even attempted it in 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? Thanks.
Some extra information:
I've already included both shared_ptr header files:
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/shared_ptr_132.hpp>
I've attempted to convert to a string and serialize it in that way but it produces the following error: boost::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;
}