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?
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?
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.
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
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