... the order of inclusion doesn't matter? |
You are correct, the order does not matter, because they have been designed that way.
how do i create [the same behavior for my files]? |
Use include guards. Each one of your header files should have the following layout:
1 2 3 4 5 6 7 8 9 10
|
// foo.hpp
// ...
#pragma once
#ifndef SAVAMPIRS_FOO_HPP
#define SAVAMPIRS_FOO_HPP
// class definitions, function prototypes, and extern declarations go here
#endif
|
The item on line 4 is useful on a lot of compilers to do what you want, but it doesn't work with all compilers. (It is still good to have there just in case it does work.)
Line 5 says "everything from here to the matching #endif on line 10 only gets compiled if the symbol 'SAVAVAMPIRS_FOO_HPP' is
not already defined."
The first time the file is #included in your project, your special symbol is not yet defined, so everything between lines 5 and 10 does get compiled.
Line 6 actually defines the symbol, so if the file gets #included again, nothing between lines 5 and 10 can get compiled.
Make sure to use a different symbol for each header file.
Also, make sure that your symbol is unique -- you don't want anyone else to #define it elsewhere.
About precompiled headers |
The term "precompiled headers" actually means something other than what you want. A precompiled header does not actually need to be included, because the compiler already knows what is in it. This is another topic entirely so you can forget about it for now.
What you are asking about is how to "prevent multiple includes" or how to "prevent the same file from being included more than once".
Hope this helps.