Use existing code range in cpp file as example for

2019-09-03 07:23发布

问题:

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  

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.

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
//! }@
...

回答1:

As pointed out by albert (comments above) \snippet can be used. A full example can be found here https://stackoverflow.com/a/16034375/356726

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.



标签: c++ doxygen