Header Files And Header Guards Flashcards
Header files
Propregage declarations to code files, allow us to put declaration in one location and then impart them whenever we need them
Header files consist of
Header guard and content of header file (forward declarations)
Headers and code files
It should be added using quotes not brackets
Angled brackets
Used to tell the preprocessor that we are including a header file that was included with the compiler
Double quotes
Tells the preprocessor that this is user-defined header file
Transitive
Includes header files that are inside of header file, added implicitly
Order of #includes
User defined, 3ed party library, standard library, added implicitly
Best practices of header files
- include header guards
- do not define variables and functions in header files
- name with the same name as source files association
- each header should have specific job and be independent
- mind which files you should explicitly include
- each header should compile on its own
- only #include what you need
- do not #include .cpp files
Header guards
Conditional compilation directives that take #ifndef, #define, #endif; they are named in all caps using underscores
Goal of header guards
Prevent a code file from receiving more than one copy of a guard header
pragma once
Serves the same purpose as header guards