添加包含保护会破坏构建 [英] Adding an include guard breaks the build

查看:34
本文介绍了添加包含保护会破坏构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将#ifndef..#define..#endif 添加到我的项目文件中,但编译器失败.一旦我删除它或在定义中放置任何其他名称,它就可以正常编译.可能是什么问题呢?

I added #ifndef..#define..#endif to a file of my project and the compiler fails. As soon as I remove it or put any other name in the define it compiles fine. What could be the problem?

听起来文件已经声明了,但我不知道在哪里.我可以删除它,但我真的很想知道为什么会这样.

Sounds like the file is already declared, but I do not know where. I'm fine just removing it, but I really want to know why this is happening.

error: expected class-name before ‘{’ token
error: ‘QDesignerFormEditorInterface’ has not been declared

还有一些其他错误.

我实际上使用的是 Qt 中的一个示例,自定义小部件插件示例".

I am actually using an example from Qt, "Custom Widget Plugin Example".

不同之处在于我将自己的类用于自定义小部件(.h、.cpp 和 .ui 文件).

The difference is I am using my own class for the custom widget (.h, .cpp and .ui file).

它可能与包含 2 个包含的文件有关,尽管示例就是这样做的.

It might have to do with the file that has 2 includes, though that is how the example did it.

推荐答案

此宏是否用作 包含保护?如果是这样,听起来您是在复制其他地方使用的名称.当人们不考虑包含保护必须具有的范围时,这是一个常见问题——您应该在其中包含更多信息,而不仅仅是文件名.

Is this macro used as an include guard? If so, it sounds like you're duplicating a name used elsewhere. This is a common problem when people don't think about the scope an include guard must have—you should include much more information in it than just the file name.

包括后卫进球:

  • 在创建标题时生成一次
  • 再也不用想了
  • 重复的机会小于您中奖的机会

错误的包含保护名称(对于文件config.h"):

Bad include guard names (for file "config.h"):

  • CONFIG_H
    • 太笼统了
    • 所有保留,还有很多一般
    • all reserved, still much too general
    • 更好,不太可能在不相关的项目中重复
    • 但仍然没有路径信息,容易在大型项目中复制

    好的包含保护名称(对于文件config.h"):

    Good include guard names (for file "config.h"):

    • PATE_20091116_142045
      • 那是<姓氏>_<日期>_<时间>
      • 甚至不需要项目、路径、文件名信息
      • 易于打字
        • 如果您的编辑器具有插入日期功能,您可以非常快速地输入"它
        • 生成时包含一个序列号,如果你需要每秒生成一个以上
        • 从实际的UUID生成
          • 具有普遍独特性的有力保证

          这篇关于添加包含保护会破坏构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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