Should I use #include in headers?

后端 未结 9 1192
甜味超标
甜味超标 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 04:56

    What I normally do is make a single include file that includes all necessary dependencies in the right order. So I might have:

    #ifndef _PROJECT_H_
    #define _PROJECT_H_
    #include 
    #include "my_project_types.h"
    #include "my_project_implementation_prototypes.h"
    #endif
    

    All in project.h. Now project.h can be included anywhere with no order requirements but I still have the luxury of having my dependencies, types, and API function prototypes in different headers.

提交回复
热议问题