71

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?

Etienne Dechamps
  • 24,037
  • 4
  • 32
  • 31
  • I think that only works for C++/CLI, the .xml file must have the same name as the *assembly*. – Hans Passant Dec 23 '11 at 20:23
  • 1
    on the contrary: C++ Intellisense should work and C++/CLI isn't (yet?) supported in VS2010. See http://connect.microsoft.com/VisualStudio/feedback/details/501921/c-cli-intellisense – surfen Mar 14 '12 at 10:08
  • No definitive answer to this question? – Ian Medeiros Mar 08 '13 at 17:59
  • 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 Aug 06 '17 at 18:14

5 Answers5

17

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.

J3soon
  • 3,013
  • 2
  • 29
  • 49
Marcus10110
  • 509
  • 4
  • 12
  • 1
    Ah, so they *could* add it to the re-architectured IDE after all. I wonder if they will have enough consideration to fix it for VS2010 with a service pack. – Synetech Jun 06 '13 at 13:56
  • Also, if you want to quick-add those comments like you can in C# by typing ///, you can with GhostDoc – Marcus10110 Nov 23 '13 at 02:36
  • 4
    There is also [CppTripleSlash](https://visualstudiogallery.msdn.microsoft.com/22333333-fd6f-4dcb-8223-52701eddd7ad) to quickly add those comments – tcb Apr 16 '15 at 16:42
  • 1
    Downvoted. This feature has been available in Visual C++ 2010 as well, possibly earlier versions. I am regularly using 2010 and both double slash // and C-style comments show up in IntelliSense IF you put them in the header file (not implementation) above functions or methods. – Jon Harbour Aug 06 '17 at 18:11
  • My reply specifically refers to xml style code comments, which are new in VS2012. I agree that the basic comments directly above the function declaration has been working long before that. https://msdn.microsoft.com/en-us/library/hh409293(v=vs.110).aspx#Anchor_5 See the section "Richer IntelliSense Tooltips." – Marcus10110 Aug 08 '17 at 21:32
15

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

Maciej Szpakowski
  • 571
  • 1
  • 7
  • 22
  • Also, if you want Intellisense to show up doc for something from a different module, you have to write a comment in the header file. I write this in a comment becasause SO syntax for images is broken. – Maciej Szpakowski Jan 07 '17 at 01:33
  • 4
    Does it still work in VS 2019? I don't see the comments anymore. – Dan M. Aug 30 '19 at 13:38
  • @DanM. Yes, I can confirm the comments above the function declaration, the function prototype, and the variable all show up in IntelliSense in VS2019. 16.3.1, with no extensions installed, as of May 2021. Comments above function prototypes will supersede the comments above function declarations though. – tom_mai78101 May 09 '21 at 01:57
12

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

};
pixelgrease
  • 1,940
  • 23
  • 26
Ian Medeiros
  • 1,746
  • 9
  • 24
  • 1
    Visual Assist is awesome! Can't imagine using VS without it now :) – Nerdtron Dec 23 '11 at 17:05
  • 5
    @Drahakar sure it does. It provides one way to make it work. It requires a third party addon, but it is an answer to the question. The question wasn't, "how do I do this without using any addons" :) – Nerdtron Dec 23 '11 at 17:06
  • 27
    Well, my question was about Intellisense. Visual Assist is not Intellisense. I'm not against Visual Assist in itself, but I was looking for a more general solution so that developers who don't have Visual Assist can still see the documentation. – Etienne Dechamps Dec 23 '11 at 17:34
5

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.

Jesse Chisholm
  • 3,857
  • 1
  • 35
  • 29
4

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://learn.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://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview
  • What an attempt at getting Necromancer badge! Link to a Polish version of ms website and a link about c# instead of c++ – Dmitry Avtonomov Jul 02 '20 at 00:20
  • 4
    I had corrected link to english version. Can't really get used to msdn displaying native language now. Anyways, link to c# documentation tags is perfectly valid as those tags are similar for C++. Moreover, separate documentation for IntelliSense in C++ does not exist at the time of writing this post. I do not think it is kind to tell people that they hunt some points or badges. I am quite excited and happy for this new feature and I think many people are. Yes I am new user trying to get some activity on the forum. No reason to be sarcastic. – Andrey Borisovich Jul 08 '20 at 23:23