一 一般写法
通常注释写在代码前面,例如
/** @brief int value a */
int a;
int b;
二 写在代码后面
int a; /** @brief int value a */
int b;
此写法当Doxygen生成文档时其实并不是修饰的a,而是b,如果此时希望能正确修饰a,写法如下:
int a; /**< @brief int value a */
int b;
注释开始的位置需要加上<。
三 写在其他位置
注释除了前面和后面之外,Doxygen还支持识别写在其他位置的注释,此时需要一些特殊命令的支持。Doxygen支持很多命令,类似于C++的标识符,例如前面的brief就是Doxygen支持的命令之一,命令必须以@或者\开头,后面再详细探究,这里不展开。
// a.hpp
class Demo{};
// b.hpp
/**
* @class Demo
* @brief describe it in some other place.
*
*/
如上,在b.hpp中的注释可以修饰a.hpp中的Demo类。提前是b.hpp的位置能够被Doxygen读取到即可。这里使用了特殊命令class,用于Class类型,针对其他类型也有相应的特殊命令:
\structto document a C-struct.\unionto document a union.\enumto document an enumeration type.\fnto document a function.\varto document a variable or typedef or enum value.\defto document a #define.\typedefto document a type definition.\fileto document a file.\namespaceto document a namespace.\packageto document a Java package.\interfaceto document an IDL interface.
四 参考
本文深入探讨了Doxygen注释的多种写法,包括代码前、后及特殊位置的注释,并介绍了如何通过特定命令正确指向目标元素,如变量、函数、类等,帮助开发者更有效地生成代码文档。
5247

被折叠的 条评论
为什么被折叠?



