Writing Classes to File

BCS BCS_member at pathlink.com
Mon May 8 19:32:45 PDT 2006


In article <e3o17r$1un7$1 at digitaldaemon.com>, Jeremy says...
>
>In article <e3ntd5$1nnb$1 at digitaldaemon.com>, BCS says...
>>
>>My solution is to declare a struct that has related data members in it. 
>>Then I give the class a DumpToFile method (generally named something 
>>else) that copies the data to the struct and does the writeExact thing. 
[...]
>>
>>The biggest catch is keeping the struct<->class translators up to date 
>>with new rev of the class.
>>
>><script:coffee author.GetOn(SoapBox);)>
>>
>>But that beings up my old dead horse: the "witheach" statement
>>http://www.digitalmars.com/d/archives/digitalmars/D/32232.html
>>
>><script:coffee author.GetOff(SoapBox);)>
>
>So, could you just include the struct inside your class?

that would work and would reduce the different revs catch.
>
>e.g.:
>
>struct ClassVars {
>int x, y;
>int health;
>};

I'd put the struct in the class scope as well

class
{
static sreuct args
{
}
args a;

}
>
>class someClass {
>private:
>ClassVars myVars;
>..
>public:
>void saveTo(BufferedFile someFile) {
>someFile.writeExact(&myVars, myVars.sizeof);
>}
>};
>
>And in processing that class (e.g. did this character gain some health) -- you
>could check myVars.health etc.
>

But Ohh dose that get ungly. OTOH might not be to bad if you want to spilt out
some sets of args.





More information about the Digitalmars-d mailing list