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

后端 未结 4 769
隐瞒了意图╮
隐瞒了意图╮ 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 11:19

    If I #include , I don't want to have to #include lots of other header files to get my code to compile. In callback.h you should include everything needed to compile against it. But nothing more.

    Consider whether using forward declarations in your header file (such as class GtkButton;) will suffice, allowing you to reduce the number of #include directives in the header (and, in turn, my compilation time and complexity).

提交回复
热议问题