In the boost tutorial and example of using shared pointers, they have a class A, and they create a shared pointer pointing to an object of class A
:
boost::shared_ptr<A> spa(new A);
Then they serialize it:
std::ofstream ofs(filename.c_str());
boost::archive::text_oarchive oa(ofs);
oa << spa;
So why does the class A
have to have this function?
void serialize(Archive & ar, const unsigned int /* file_version */);
The reason I want to use a shared pointer is to avoid defining this function for some of my complex classes. Currently I'm not using a shared pointer, I'm using a real pointer, and I'm actually serializing the address the pointer is pointing at.