473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Saving/Loading a class instance to file

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
3 1392
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jacob H | last post by:
Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle...
7
by: G-Factor | last post by:
Hi all I've just started learning about saving files. I got bit of a problem. The following code gives me an error about incompatible types. (Cannot covert from class character to char *). I...
4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
17
by: Aguilar, James | last post by:
My previous example used the concept of a Shape class heirarchy, so I will continue with that. Suppose I have something like fifty different shapes, and I am trying to instantiate one of them. ...
1
by: Tom | last post by:
I have a large application; lots of forms, multiple dynamic DLLs, etc. I also have, in the appliation, a general 'Preferences' class object (which is in itself a separate DLL, and I just include a...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
6
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data)...
3
by: shuisheng | last post by:
Dear All, Assume I have two classes: material and shape, as follows class Material { double density; // material attribute, may have more vector<Shape*pShape; // shape objects assocaited...
4
by: ulaskaraoz | last post by:
Hi, I have a std::map instance that I want to save into harddisk so that I donot have to recompute it each time. The map itself is keyed by a string and the values are pointers to other objects....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.