P
Peter Oliphant
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==]
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==]