#include in .h or .c / .cpp?

后端 未结 4 777
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 10:29

When coding in either C or C++, where should I have the #include\'s?

callback.h:

#ifndef _CALLBACK_H_
#define _CALLBACK_H_

#include <         


        
4条回答
  •  没有蜡笔的小新
    2020-12-12 10:57

    Put as many includes in your cpp as possible and only the ones that are needed by the hpp file in the hpp. I believe this will help to speed up compilation, as hpp files will be cross-referenced less.

    Also consider using forward declarations in your hpp file to further reduce the include dependency chain.

提交回复
热议问题