|
-
May 3rd, 2010, 12:18 PM
#6
Re: saving an unknown object of POD in binary format
 Originally Posted by kempofighter
I'm not so sure about that since the OP did say that he was dealing with POD objects. Perhaps we are making the solution more complex than necessary? Why is the original template function needed since we are only dealing with POD objects? Why not just cast the pointer to the object into const char* and use the stream read/write functions directly? It isn't much different than copying the POD object to and from a character array using memcpy is it?
Assuming no pointer members as I said above, then yes, it's exactly the same---and probably good enough so long as the file only persists for the length of a single program run.
However, that solution becomes insufficient if you want a file which can persist between program runs, or more generally, between machines/compilers/options which may be used to build the programs.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|