|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2008-03-25 16:19:16
Quesion is:
class Base {
...
virtual ..
}
class D1 : public Base {
}
class D2: : public Base {
}
D1 d1;
D2 d2;
d2 = d1; // can never work because d1 can't be transformed into a D2;
D1 *d1p;
Base *bp:
ar << d2p;
ar >> bp; // Can work, but creates a NEW instance of D1.
To create archives in memory, use string_stream.
Robert Ramey
"Andrei Popa" <andrei4popa_at_[hidden]> wrote in message
news:BAY103-W46B377D42D9D718F6B9C48E0FC0_at_phx.gbl...
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!
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
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