How do I preserve a comment in an example in Doxygen

眉间皱痕 提交于 2020-01-01 19:50:32

问题


I have a simple method with a comment I want to use as an example in my doxygen mainpage:

\code

    void showNum(int numToDisplay){

        // This is just a method to display a value.
        std::cout<<"Displaying Number "<<numToDisplay<<std::endl;
    }

\endcode

When a generate the docs, the mainpage will show the code example correctly but the comment will be all the way to the left edge of the main page. What character(s) do I use to force the comment to maintain its justification and display?

Thanks in advance for the help.


回答1:


Without a little more information it's going to be hard to diagnose this but a couple things to check :

  • Make sure you have a blank line preceding your code.
  • Make sure that you have four spaces indentation
  • Make sure the white space preceding your comment is not a tab

It sounds as if your code is not being interpreted as a code block (because of one of the reasons listed above). If you could post at least part of the file with the code block in it, it might help sort this out.

Here's a small example which seems to do what you want:

/**
 * @file tmp.cpp
 */

/** Brief description
 *
 * Long description of what the function does ...
 *
 * \code{.cpp}
 *
 *     void showNum(int numToDisplay){
 *
 *         // This is just a method to display a value.
 *         std::cout<<"Displaying Number "<<numToDisplay<<std::endl;
 *     }
 *
 * \endcode
 *
 */
void showNum(int numToDisplay) {
   std::cout << "Displaying Number " << numToDisplay << std::endl;
}


来源:https://stackoverflow.com/questions/32129501/how-do-i-preserve-a-comment-in-an-example-in-doxygen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!