By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,695 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,695 IT Pros & Developers. It's quick & easy.

Saving/Loading a class instance to file

P: n/a
Trying to save/load a class instance to a file is tough. The reason is
because there is no way to preserve its type other than by conventon. For
eample, one can save all the states of the members of a class instance to a
file. But when loading it up the program can only read in the values stored.
It has no idea what kind of class they came from, and there is no way to
save info (that I'm aware of) that let can allow the application to figure
this out at runtime. The programmer must therefore figure out a saving
convention and then load the approriate type according to his convention.

This is especially a problem with templated classes. This is because an
instance of a templated class requires it be made concrete at compile time.
It is therefore impossible to write a Save_To_File() member method for a
templated class, since one can't override it for different types, and there
is no way of constructing an arbitray template class (i.e., one where the
template arguments are variables).

Anybody have clever ways of saving a class instance in such a way it can be
restored without knowing ahead of time what class it came from in the first
place? For example, can I save something to a file that when loaded can let
me build at runtime, say, an arbitrary class or data type?

[==P==]
Nov 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sounds to me you are trying to reinvent what is already prescribed and
available. Take a look at the IPersist* family of interfaces.

Brian
Nov 24 '05 #2

P: n/a
Thanks Brian!

Indeed, I'll look this up. So far the MSDN2 does list IPersist, but doesn't
really describe it, it just --- IS. I also see I should study IMoniker. If
you know of any sources of sample code, preferably in /clr managed VS
C++.NET (Express), that would be great too... : )

[==P==]

"Brian Muth" <bm***@mvps.org> wrote in message
news:OU**************@TK2MSFTNGP10.phx.gbl...
Sounds to me you are trying to reinvent what is already prescribed and
available. Take a look at the IPersist* family of interfaces.

Brian

Nov 28 '05 #3

P: n/a
The best reference for IMoniker is "Inside OLE" by Kraig Brockshmidt. The
entire text of this book is available on one of the older MSDN Library
CD's... I forget which one.

Brian
Nov 28 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.