Thread: How do you organize your code

  1. #1
    Shadow12345
    Guest

    How do you organize your code

    I am finally getting to the point where I am writing so much code it cannot possibly be contained in one .cpp file. I don't know for sure how things are supposed to be set up. I am trying to have a .h file that declares my classes and functions, and then have a .cpp file that includes all of the implementations of thsoe defined in the header. Also in the header, I am putting all of the other includes that are necessary to the project, i.e vector, conio, fstream, etc.

    Is there anything I am missing here?

  2. #2
    I dont have my book in front of me but im sure if you would just read up a lil you would gain comfidence that your organized enough, try www.google.com and search for c++ code organization

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Depends.
    For larger projects I usually place one class in each file (with a header file each), have one file for your own datatypes (typedef:ed things), one for definitions/macros and of course one for my main function + eventual smaller functions.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    BOOKS?

    Can some of you recommend a book with at least a chapter or two covering this subject?

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    Can't recommend a book, but Magos does what I do. Put every class in its own .h and .cpp pair of files. This, i think, helps tp stay in an object oriented way of thinking about your application and it's objects.

    CPlayer class has: Player.h and Player.cpp
    CChess class has: Chess.h and Chess.cpp

    etc...

    Give this a try and see if you find your large projects become more managable.
    Best Regards,

    Bonkey

  6. #6
    Jesse Liberty's C++ in 21 days explains this very well.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    remember, don't compile your .h files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM