Is it reasonable to put custom headers higher in include section than standard headers?
For example include section in someclass.hpp:
#include "someclass.h"
#include "global.h"
#include <iostream>
#include <string>
Is it best practice? What is the profit if it is?
The reason is that if you forget to include a dependent header in
someclass.h, then whatever implementation file includes it as the first header, will get a warning/error of undefined or undeclared type, and whatnot. If you include other headers first, then you could be masking that fact – supposing the included headers define the required types, functions, etc. Example:my_type.h:
someclass.h:
someclass.cpp:
This will compile fine. But imagine you want to use use
SomeClassin your program. If you don’t includemy_type.hbefore includingsomeclass.h, you’ll get a compiler error sayingmy_typeis undefined. Example: