-
OOP & File scanning.
Im building a small application that, has 3 classes: MEMBER, VIP, ADMIN.
they also derive in that order., a vip is a member, and a admin is a vip.
but ofcourse how can my program be usefull if i cant save my data to a file? so i decided to start thinking of ways to save it to a file.
the binary way seems the best to me... one problem, when the program runs you are prompted to either
REGISTER
LOGIN
EXIT
LOGIN will be the problem... how can i check the saved password in my binary file if i dont know if the user is a vip, member, or admin? cause these classes have diffrent sizes... i might put my file pointer at the wrong location.
anny advice, tips or solutions?
If i am unclear in anny way, please tell me so i can try and rephrase
-
Why does binary seem the best to you? If you are going to have a class hierarchy, either all the data should be stored in the base class (so they all have the same size) or you should not be saving out in binary.
In this situation my guess is saving out in text mode would be better.
-
actualy i didnt rly think, i just wanted to do it in binary.
to bad u cant
-
You can only save Plain Old Data types directly to file anyway. POD's are not entirely Objects, as far as OOP is concerned. Saving a typical class directly to a file will not work.
You can still serialize a class into a compact binary representation. You can use a single POD struct to do this, and have every serializable class be convertible to that struct. Or you can handle the serialization in it's own class/set of functions.
Serialization allows you to compactly store your classes to a file, or send them through a network. But this comes at the cost of making the information illegible when viewed by human eyes, and therefore harder to debug. For non production quality code, it is almost always better to use text, or a markup language (like XML) to store classes in files.
Note: I used a few technical terms in this post, that you probably do not know. You can search for these terms to learn more about them, as I'm not up for giving definitions or links. What you find will likely help you implement what you want, if you still want to.
-
Yeah... If i still want to :P