Hi there,
I have a small hierarchy of classes that are serializable. I wanted to implement in base class a ::copyFrom method that can copy any data
from a pointer to "this" object. The idea behind was to save the "from" pointed object to an archive and then restore the saved data in "this".
Saving the input pointer was not a problem but restoring the data in "this" object was a really problem.
Since loading *this will call ::load of a base class, I created an temporary shared_ptr around "this".
This way the appropriate ::load of the derived class was called.
But unfortunately after executing "iarchive >> p;" the px of p doesn't point anymore to "this".
I don't know why?
Basic code looks like:
baseClass::copyFrom (const BaseClass* from)
{
//save
*from
//restore the saved data in "this"
boost::shared_ptr<baseClass> p(this, baseClass::pseudo_deleter());
iarchive >> p;
}
pseudo_deleter dose nothing.
Does anybody know way this happen? Has anybody a better idea how to implement this method?
I tried also to replace the shared_pt with shared_from_this but the results are the same.
An other problem that I ignored for the moment is that the used archive should be a kind of memory stream that has no file/disk operations behind.
Tia,
Andrei
Get news, entertainment and everything you care about at Live.com. Check it out!