如何编写出现在 Intellisense 中的 C++ 注释?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8618571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:52:57  来源:igfitidea点击:

How to write C++ comments that show up in Intellisense?

c++visual-studiovisual-studio-2010documentationintellisense

提问by Etienne Dechamps

I'm programming in C++ using Visual Studio 2010 Ultimate. I want to document some functions and I want the documentation to show up in Intellisense.

我正在使用 Visual Studio 2010 Ultimate 用 C++ 进行编程。我想记录一些函数,并且我希望文档显示在 Intellisense 中。

According to MSDN, I just need to put the comment before the declaration or after it on the same line. So I tried this:

根据MSDN,我只需要在声明之前或之后将评论放在同一行。所以我试过这个:

// This is a test.
void foo();
void bar() { foo(); }

When moving my mouse over foo(), the comment doesn't appear in the tooltip. I also tried:

将鼠标移到 上时foo(),注释不会出现在工具提示中。我也试过:

  • ///
  • <summary></summary>tags
  • Building with /doc(by setting the "Generate XML documentation files" option in the project settings)

I've had no luck so far. Does anyone know a way to make this work?

到目前为止,我没有运气。有谁知道使这项工作的方法?

回答by Marcus10110

This now supported in VS 2012!

这现在在 VS 2012 中得到支持!

Previously, XML tags in the comments were only read in by C++/CLI, not plain old C++. VS 2012 now brings at least some of this into regular C++ - it is in the What's New in Visual Studio 2012and in the MSDN docs: XML Documentation (Visual C++).

以前,注释中的 XML 标签只能由 C++/CLI 读取,而不是普通的旧 C++。VS 2012 现在至少将其中的一些带入了常规 C++ - 它位于 Visual Studio 2012 的新增功能和 MSDN 文档:XML 文档 (Visual C++) 中

I've tested it with my own application in 2012 ultimate, and I can confirm that the summary, para, and seealso tags are all pulled out an formatted for tooltips.

我已经在 2012 Ultimate 中用我自己的应用程序对其进行了测试,我可以确认摘要、段落和 seealso 标签都被拉出一个格式化的工具提示。

回答by Maciej Szpakowski

I'm not sure which version of Visual Studio introduced that but in VS 2015 you can simply put comment above a function, method, class, struct, union, enum class, namespaceor even individual variables (locals too) and it will be shown by Intellisense. If you want to document something from a different module, you have to write a comment in the header file. Examples: FunctionClassVariable

我不确定哪个版本的 Visual Studio 引入了它,但在 VS 2015 中,您可以简单地将注释放在、、、、、甚至单个变量(本地变量)上方function,它会由 Intellisense 显示。如果你想记录来自不同模块的东西,你必须在头文件中写一个注释。例子: methodclassstructunionenum classnamespace功能班级多变的

回答by Ian Medeiros

Try installing Visual Assistand using doxygenstyle:

尝试安装Visual Assist并使用doxygen样式:

/**
* COMMENT DESCRIBING A CLASS
**/
class Foo
{
   public:
      /**
      *   \brief A foo method.
      *
      *   More complete description of foo.
      *   
      *   \param i A foo parameter.
      *   \return An int
      *
      **/
      int fooMethod(int i);

   private:
      int i; /*!< COMENT OF A MEMBER */

};

回答by Jesse Chisholm

I haven't used VS2010 is too many years to remember whether this worked there or not. But what I have done for years in many different version of VS is ...:

我没有使用 VS2010 太多年了,不记得这是否在那里有效。但是我多年来在许多不同版本的 VS 中所做的是......:

#pragma region foo(float)
/// <summary> .... </summary>
/// <param name="bar"> .... </param>
/// <returns> .... </returns>
int foo(float bar)
{
    // stuff
}
#pragma endregion

In other words, manually putting in exactly what Visual Studio will automagically put in for C# codefor you.

换句话说,手动输入 Visual Studio 将为您自动输入的C# 代码

Then give the Intellisense engine a minute or so to reparse the file. Doing a build will force it to reparse, of course.

然后给 Intellisense 引擎一分钟左右的时间来重新解析文件。当然,进行构建将迫使它重新解析。

As I recall, this works in the most recent VS2010 Express Community, but I don't recall whether it worked in VS2010 Ultimate.

我记得,这适用于最新的 VS2010 Express 社区,但我不记得它是否适用于 VS2010 Ultimate。

回答by Andrey Borisovich

Old question but without accepted answer, so maybe this will help:

老问题,但没有被接受的答案,所以也许这会有所帮助:

  1. Currently in Visual Studio 2019 you can manually write xml documentation that is displayed in the IntelliSense using supported tags from: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/recommended-tags-for-documentation-comments
  2. Support for autogenerated xml documentation after typing "///" is coming in Visual Studio 2019 version 16.6 that is currently in the PreRelease state. Check for details: https://docs.microsoft.com/pl-pl/visualstudio/releases/2019/release-notes-preview
  1. 目前在 Visual Studio 2019 中,您可以使用以下支持的标签手动编写显示在 IntelliSense 中的 xml 文档:https: //docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/recommended-tags-文档注释
  2. 当前处于 PreRelease 状态的 Visual Studio 2019 版本 16.6 将支持在键入“////”后自动生成的 xml 文档。查看详情:https: //docs.microsoft.com/pl-pl/visualstudio/releases/2019/release-notes-preview