Writing Classes to File
Jeremy
Jeremy_member at pathlink.com
Mon May 8 11:02:16 PDT 2006
In article <e3o0d4$1tdc$1 at digitaldaemon.com>, Sean Kelly says...
>
>Jeremy wrote:
>> Is there a way I can just write a whole class to a file?
>>
>> For example, why can't I do:
>>
>> file.writeExact(someClass, someClass.sizeof);
>>
>> This seems to just write 4 bytes, which must be the pointer.
>>
>> The compiler complains when I do this:
>>
>> file.writeExact(*someClass, (*someClass).sizeof);
>>
>> Saying that '*' is only used infront of pointers -- but aren't class always
>> represented with pointers?
>
>They are, but I think they don't have the same semantics as pointers
>insofar as the type is concerned. This is what inspired me to make the
>"isizeof" proposal a few weeks ago, as there's currently no way to get a
>class' size at compile-time. However, you can get it a run-time via:
>
>someClass.classinfo.init.length
>
>
>Sean
Interesting... so could this be done:
file.writeExact(someClass, someClass.classinfo.init.length);
to write the entire class to a file? (I'd like to do some zlib compression on it
too :-D )
More information about the Digitalmars-d
mailing list