Re: CreateObject confused
"RB" <NoMail@NoSpam> wrote in message
news:eJDD4lLBLHA.1972@TK2MSFTNGP02.phx.gbl...
........................ For example, the MFC framework (which was
compiled
in 2008 without knowing your class name) creates your CFileHandlingDoc at
startup, but it does so without a
CFileHandlingDoc* p = new CFileHandlingDoc();
statement. The CRuntimeClass provides the needed data about the object.
The same ability is used by CArchive to create objects from the file
stream. Instead of having a 'new' statement for each possible class it
uses CreateObject to create all objects. Scott McPhillips [VC++ MVP]
Ok, that verbalizes more clearly, but if I may be so curious why does
my CMapStringToString Object which is already in existence need
CreateObject to create a object to receive my serialized read ?
It appears the WriteClass and ReadClass (called by WriteObject or
ReadObject ) has no problem fetching the CmStS's Cruntime data
from my file. So after that, I don't see why another object needs created
before actually reading the CMap in ?
I have not delved into this deserialize code, but I suspect the answer is
that CArchive is highly generalized code that does not know or care about
your CmStS member. It just makes the map object, then lets your >>
statement take care of where it goes (via a copy c'tor). That would be the
way to code it generically.
--
Scott McPhillips [VC++ MVP]