Eclipse 中的新 .h 文件生成 #define 常量
所以我正在努力学习 C++,并开始使用 Eclipse。当我创建 .h 文件时,我在顶部得到了这个奇怪的 #define 常量:
#ifndef CLASSNAME_H_
#define CLASSNAME_H_
#endif /* CLASSNAME_H_ */
那么,给出了什么?我应该使用 CLASSNAME_H_ 来做什么吗?
(我应该注意,“类名”只是一个填充符。因此,例如,我最新的类是 Person.h,我现在有 PERSON_H_)
So I'm chugging along in learning C++ and I'm starting to use Eclipse. As I create my .h files, I get this strange #define constant at the top:
#ifndef CLASSNAME_H_
#define CLASSNAME_H_
#endif /* CLASSNAME_H_ */
So, what gives? Am I supposed to use CLASSNAME_H_ for something?
(I should note that "classname" is just a filler. So, for example, my latest class was Person.h and I now have PERSON_H_)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个标准构造,用于防止重新包含头文件,我认为您可能需要将 CLASSNAME_H_ 重命名为更独特的名称。
或者你的头文件也叫classname.h?
编辑:好的,所以我现在看到类名不是实际值,而是一个示例。
在这种情况下,不,你根本不需要担心这个,只需忽略他们,他们就会完成他们的工作。
This is a standard construct used to guard against re-inclusion of your header files, I think you are probably expected to rename CLASSNAME_H_ to something more unique.
or is your header file also called classname.h?
Edit: ok so I see now that classname wasn't the actual value, but rather an example.
In that case, NO, you shouldn't need to worry about this at all just ignore them and they will do their job.
它只是为了确保在编译过程中多次包含该文件时,内容不会被多重定义。您不使用 CLASSNAME_H 做任何事情,它只是将该文件的内容添加到书尾。
Its just there to ensure that when that file is included multiple times during compilation that the contents aren't multiply defined. You don't use the CLASSNAME_H for anything, it just bookends the contents of that file.