命名包括保护 [英] Naming Include Guards

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

问题描述

C ++如何包含通常命名的警卫?我倾向于看到很多:

How are C++ include guards typically named? I tend to see this a lot:

#ifndef FOO_H
#define FOO_H

// ...

#endif

认为这是非常直观。没有看到文件名,很难判断 FOO_H 是否存在以及它的名称是什么。

However, I don't think that's very intuitive. Without seeing the file name it's difficult to tell what FOO_H is there for and what its name refers to.

考虑最佳实践?

推荐答案

根据我自己的经验,约定是在包含它们的头文件之后,

From my own experience, the convention is to name the inclusion guards after the header file containing them with the exception that the name is all in caps and the period is replaced with an underscore.

所以 test.h 变成了 TEST_H

现实生活中的例子包括Qt Creator,当自动生成类头文件。

Real life examples of this include Qt Creator, which follows this convention when auto-generating class header files.

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

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