Writing Classes to File

Sean Kelly sean at f4.ca
Mon May 8 10:50:25 PDT 2006


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



More information about the Digitalmars-d mailing list