如何编写漂亮的 C++ 注释的示例
examples of how to write beautiful c++ comments
也许是愚蠢的问题,但有没有办法写出好看的(短)格式为 C++ 函数、标头、变量编写注释?任何视觉示例?
这里好看是什么意思?我是这样做的..
int c;//! loop Counter
/**
* compares (XOR) two Types
* return boolean result
*/
bool compare(Type l, Type r);
它的 doxygen 格式。在 Comment 中有一些用于记录代码的填充格式。Doxygen是一个,另一个是naturaldocs。还有更多。这是你的味道。您甚至可能喜欢naturaldocs格式。
/*
Function: Compare
Compares two Types
Parameters:
l - lhs
r - rhs.
Returns:
boolean result
*/
bool compare(Type l, Type r);
DOC++格式也更相似。
/** Comparison
Compare two Types
@param l Type lhs
@param r Type rhs
@return boolean result
*/
bool compare(Type l, Type r);
只需仅使用一种格式并坚持使用即可。
我更喜欢使用这种风格:
/**
* Class name
* Description
*/
class MyClass{
}
有些人会认为,最漂亮的评论是那些在整个程序中保持一致的评论。我更喜欢使用正斜杠:
// -- short concise comments in single lines like this
// -----------------------------------------
//
// Sectional Dividers Like This
//
// -----------------------------------------
也就是说,如果您希望从评论中生成文档,这些将无济于事。
我使用以下样式:
对于方法:
/**
* Method description.
* @param param1 param1 description
* @param param2 param2 description
* @return return description
* @since date since method is created
* @author who have made this method.
*/
对于变量:
/** variables description **/
对于类:
/**
* Class description.
* @since date since class is created
* @author who have made this class.
*/
最好的方法是以这样的方式进行,即某些自动化工具可以提取它们并创建交叉链接的文档。看看氧气
看看 http://www.doxygen.nl/。 基本上,JavaDoc格式的起飞,其中格式在一定程度上被解释为帮助文件。
我相信自我记录代码,但一些精通的评论会有很大帮助。
相关文章:
- Visual Studio 2019:插入多个C++风格的单行注释
- VSCode 中带有 C/C++ 扩展名的多行注释缩进错误
- 如果我注释掉换行符,为什么'string'会成为一个不合格的变量
- 为什么 ## aka 令牌粘贴运算符不适用于 C 和 C++ 中的注释?
- 在 // C++注释中使用 \\ 是否合法?(C++评论中的LaTeX方程)
- 注释一行使代码工作,而没有它,代码不起作用
- 使用 Doxygen 在不同文件中注释函数
- 如何设置叮当格式的注释编译指示,以免触及多行doxygen注释?
- Qt - 带有注释的 JSON
- Visual Studio Community 代码分析的质量与 SAL 注释
- 如何阻止 ReSharper 在 C++ 中格式化多行注释
- C++,在多行代码段中注释
- 使用 Python 和正则表达式提取源代码中的C++注释
- 使用 C++ std::sregex_token_iterator 提取 HTML 注释
- C(嵌入式):注释 FreeRTOS 的 RootTask 时代码大小不会缩小
- 我需要帮助创建一个评分系统,但它一直给我一个错误,注释掉的整数是给我带来麻烦的部分
- 如何确保 C/C++ 代码中不会缺少 doxygen 风格的文档注释?
- 删除被注释掉的代码,而不是实际的赞美
- Cpp检查规则不显示 #define,注释
- Visual Studio 2017 是否有用于创建单行注释的特定键盘组合?