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?
Printable View
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
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.)