Thread: OOP & File scanning.

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    86

    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

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    86
    actualy i didnt rly think, i just wanted to do it in binary.
    to bad u cant

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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.
    Last edited by King Mir; 03-24-2007 at 01:42 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    86
    Yeah... If i still want to :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. file processing updating record error
    By uuser in forum C Programming
    Replies: 2
    Last Post: 04-27-2003, 12:13 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM