68
votes

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.

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

// 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:

  • ///
  • <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?

5
I think that only works for C++/CLI, the .xml file must have the same name as the assembly.Hans Passant
on the contrary: C++ Intellisense should work and C++/CLI isn't (yet?) supported in VS2010. See connect.microsoft.com/VisualStudio/feedback/details/501921/…surfen
No definitive answer to this question?Ian Medeiros
Both double slash // and C-style comments show up in IntelliSense if you put them in the header file above functions or methods. (p.s. I'm responding necro because I still use 2010, like many devs). Thanks for bringing this up.Jon Harbour

5 Answers

17
votes

This now supported in 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 2012 and in the MSDN docs: XML Documentation (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.

15
votes

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, namespace or 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: Function Class Variable

11
votes

Try installing Visual Assist and using doxygen style:

/**
* 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 */

};
4
votes

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 ...:

#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# code for you.

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

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

2
votes

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/en-us/visualstudio/releases/2019/release-notes-preview