Thread: saving a class... binary style

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    saving a class... binary style

    if i was to output like this

    PHP Code:
    class cRect{
         public:
             
    cRect(int xint yint wint h);
             
    int x,y,w,h;
    };

    class 
    sRect//or just struct sRect
          
    public:
             
    int x,y,w,h;
    };
         
    ....

    cRect cr;
    sRect sr;

    ....

    ofstream binout("file.dat",ios::out|ios::binary);
    binout.write( (char*)&sRectsizeof(sRect));
    binout.write( (char*)&cRectsizeof(cRect));

    .... 
    would these both do the same thing?? basically what i'm asking is if having methods affects the size of a class for these purposes.

    if this worked couldn't i use sRect and cRect interchangably in I/O?

    thanks in advance

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >would these both do the same thing??

    it should!

    >basically what i'm asking is if having methods affects the size of a class for these purposes.

    methods should absolutely add NO size to the class,
    if they do get a nw compiler.

    if thats what your asking.

    >if this worked couldn't i use sRect and cRect interchangably in I/O?

    theoritically yes.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Saving linked lists to a binary file
    By kotoko in forum C Programming
    Replies: 1
    Last Post: 06-14-2008, 06:41 PM
  2. Saving binary tree data to disk
    By balazsbotond in forum C++ Programming
    Replies: 9
    Last Post: 12-09-2007, 09:46 AM
  3. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM