Boost logo

Boost Users :

From: Andrei Popa (andrei4popa_at_[hidden])
Date: 2008-03-25 13:07:34


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

_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net