使用cpp文件中的现有代码范围作为文档示例 [英] Use existing code range in cpp file as example for documentation
问题描述
我可以在doxygen文档中使用现有代码范围(表示 cpp
文件中的几行代码)作为示例吗?
Can I use an existing code range (means some lines of code from a cpp
file) as example in the doxygen docu?
/*!
* \brief My Foo class
* \details More about foo
* \example?? Foo used like here, some LOC from cpp follow (how can I do that??)
*/
class Foo
我想显示3-10行现有代码,说明我如何使用 Foo
。这些3-10行应该来自 cpp
文件。
I want to show 3-10 lines of existing code of how I have used Foo
. Those 3-10 line are supposed to come from a cpp
file.
我知道我必须标记 cpp
文件和 \file
,但是如何在其中引用某些代码行?
I understand that I have to tag the very cpp
file with \file
, but how do I refer to some lines of code there?
这样的事情(错误的伪代码,因为我不知道该怎么做)
Something like this (incorrect pseudo code, as I have no idea how to do it)
somewhereelse.cpp
...
...
//! \example Foo (supposed to display with Foo docu). This is how Foo is used
//! @{
Foo f;
f.init(); // init first
f.start(); // then start
//! }@
...
推荐答案
如所指出可以使用albert out(上面的评论) \snippet
。可以在此处找到完整的示例 https://stackoverflow.com/a/16034375/356726
As pointed out by albert (comments above) \snippet
can be used. A full example can be found here https://stackoverflow.com/a/16034375/356726
您引用一个文件,并在该文件(在我的方案中为 .cpp
)中,将块标记为 [ ]
括号。然后它将显示为代码块。
You refer to a file and in that file (.cpp
in my scenario) you mark the block by []
brackets. It then will appear as code block.
这篇关于使用cpp文件中的现有代码范围作为文档示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!