包括头和Main.h [英] Including headers and Main.h

查看:200
本文介绍了包括头和Main.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定不确定这是正确的方式,甚至正确的方式,但我已经看到这一点,并开始使用它,说你有6个文件

Ok not sure if this is the right way or even a correct way but i have seen this and started to use it, Say you have 6 files

main.cpp
main.h

car.cpp
car.h

speed.cpp
speed.h




  • 第一 - 你应该有main.h吗?

  • 第二 - 如果main.h有#include car.h和#include speed.h,那么在
    car / speed.cpp中你只需要添加#main.h (因此它
    包括car / speed.h)

  • 第三 - 你应该去那条路吗?

  • 推荐答案

    #include

    不要 #include 当你可以转发声明。如果A类;将足够,不要 #include ah

    Don't #include when you can forward-declare. If "Class A;" will suffice, don't #include a.h.

    特别是,更喜欢在头文件中转发声明,避免生成高度耦合的mega-include文件的嵌套包含。

    In particular, prefer to forward-declare in header files, avoiding nested includes which generate highly coupled mega-include files.

    另请参见 Self - 足够的头文件,在相关问题中。

    See also Self-sufficient header files, in a related question.

    这篇关于包括头和Main.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆