what is proper header use?

This is a discussion on what is proper header use? within the C++ Programming forums, part of the General Programming Boards category; Emily post has failed me again... I understand how to make and #include header files, but I'm not clear on ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    11

    what is proper header use?

    Emily post has failed me again...

    I understand how to make and #include header files, but I'm not clear on what's considered 'good practice' with header files. What are they good for?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Your header file should contain everything people who want to use your big pile of code would need to make it work: function prototypes, class definitions, struct/enum definitions, and templates. The code itself would get compiled separately, so it's in your .cpp file.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You should also include header guards in your header files to prevent errors from multiple inclusion:
    Code:
    #ifndef SOME_UNIQUE_NAME_GOES_HERE
    #define SOME_UNIQUE_NAME_GOES_HERE
    
    // Put your header file code here.
    
    #endif  // SOME_UNIQUE_NAME_GOES_HERE
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    You should never put using declarations or definitions in your header files. (As a rule of thumb. There are specific instances where you will do that.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21