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

64,086

Solution 1

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.

Solution 2

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

Solution 3

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

};

Solution 4

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.

Solution 5

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
Share:
64,086
Tuval4980
Author by

Tuval4980

Updated on July 09, 2020

Comments

  • Tuval4980
    Tuval4980 almost 4 years

    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?

  • Nerdtron
    Nerdtron over 12 years
    Visual Assist is awesome! Can't imagine using VS without it now :)
  • Nerdtron
    Nerdtron over 12 years
    @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" :)
  • Tuval4980
    Tuval4980 over 12 years
    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.
  • Synetech
    Synetech almost 11 years
    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.
  • Marcus10110
    Marcus10110 over 10 years
    Also, if you want to quick-add those comments like you can in C# by typing ///, you can with GhostDoc
  • tcb
    tcb about 9 years
    There is also CppTripleSlash to quickly add those comments
  • Maciej Szpakowski
    Maciej Szpakowski over 7 years
    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.
  • Jon Harbour
    Jon Harbour almost 7 years
    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.
  • Marcus10110
    Marcus10110 almost 7 years
    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. msdn.microsoft.com/en-us/library/… See the section "Richer IntelliSense Tooltips."
  • Dan M.
    Dan M. over 4 years
    Does it still work in VS 2019? I don't see the comments anymore.
  • ThomasG
    ThomasG almost 4 years
    What an attempt at getting Necromancer badge! Link to a Polish version of ms website and a link about c# instead of c++
  • Andrey Borisovich
    Andrey Borisovich almost 4 years
    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.
  • tom_mai78101
    tom_mai78101 about 3 years
    @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.