Thread: what is proper header use?

  1. #1
    Registered User
    Join Date
    Mar 2008

    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
    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
    Toronto, ON
    You should also include header guards in your header files to prevent errors from multiple inclusion:
    // Put your header file code 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
    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!

    "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
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM