Include headers in header file?

前端 未结 3 412
春和景丽
春和景丽 2021-01-04 21:55

I have several libraries made by myself (a geometry library, a linked list library, etc). I want to make a header file to include them all in one lib.h. Could I do something

3条回答
  •  死守一世寂寞
    2021-01-04 22:01

    The "right way" to include (in A)

    • do nothing if: A makes no references at all to B
    • do nothing if: The only reference to B is in a friend declaration
    • forward declare B if: A contains a B pointer or reference: B* myb;
    • forward declare B if: one or more functions has a B object/pointer/reference as a parameter, or as a return type: B MyFunction(B myb);
    • #include "b.h" if: B is a parent class of A
    • #include "b.h" if: A contains a B object: B myb;

    From a cplusplus.com article you should definitively read

提交回复
热议问题