This is a rather basic question, but it's one that's bugged me for awhile.
My project has a bunch of .cpp (Implementation) and .hpp (Definition) files.
I find that as I add additional classes and more class inter-dependencies, I have to #include other header files. After a week or two, I end up with #include directives in lots of places. Later, I'll try removing some of the #includes and discover that everything still works because some OTHER included class is also #including what I just removed.
Is there a simple, easy rule for putting in #includes that will stop this ugly mess from happening in the first place? What is the best practice?
For example, I've worked on projects where the Implementation .cpp file ONLY includes the corresponding Definition .hpp file, and nothing else. If there are any other .hpp files that need to be used by the Implementation .cpp, they are all referenced by the Definition .hpp file.
A standard is a repeatable, harmonised, agreed and documented way of doing something. Standards contain technical specifications or other precise criteria designed to be used consistently as a rule, guideline, or definition.
The definition of a standard is something established as a rule, example or basis of comparison. An example of standard is a guideline governing what students must learn in the 7th grade. An example of standard is a piece of music that continues to be played throughout the years.
1 : something established by authority, custom, or general consent as a model, example, or point of reference the standard of the reasonable person. 2 : something established by authority as a rule for the measure of quantity, weight, extent, value, or quality. 3 : the basis of value in a monetary system.
to perform an activity at a level that other people have to try to achieve. a company that sets the standard in overnight delivery. Synonyms and related words. To do something well or better than someone else. excel.
Some best practices:
Every header is wrapped with:
#ifndef HEADER_XXX_INCLUDED
#define HEADER_XXX_INCLUDED
...
#endif /* HEADER_XXX_INCLUDED */
Headers do not include each others in cycles
These are not necessarily "best practice", but rules which I usually follow also:
#include "..."
and before the system-wide headers, which are included as #include <...>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With