Should I use #include in headers?

后端 未结 9 1177
甜味超标
甜味超标 2020-11-22 04:55

Is it necessary to #include some file, if inside a header (*.h), types defined in this file are used?

For instance, if I use GLib and wish to use the

9条回答
  •  名媛妹妹
    2020-11-22 05:00

    During compilation preprocessor just replaces #include directive by specified file content. To prevent endless loop it should use

    #ifndef SOMEIDENTIFIER
    #define SOMEIDENTIFIER
    ....header file body........
    #endif
    

    If some header was included into another header which was included to your file than it is not necessary to explicitly include it again, because it will be included into the file recursively

提交回复
热议问题