使用 cpp 文件中的现有代码范围作为文档示例

Use existing code range in cpp file as example for documentation

我可以在 doxygen 文档中使用 现有代码范围(表示来自 cpp 文件的一些代码行)作为示例吗?

/*!
 * \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 文件。

我知道我必须用 \file 标记非常 cpp 的文件,但我如何引用那里的某些代码行?

类似这样的东西(不正确的伪代码,因为我不知道该怎么做)

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 所指出的(上面的评论)\snippet 可以使用。可以在此处找到完整示例

您引用了一个文件并在该文件中(.cpp 在我的场景中)您用 [] 括号标记了该块。然后它将显示为代码块。