Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VC++ Comments, Documentation and IntelliSense

In C#, I comment methods like this:

    /// <summary>
    /// Does absolutely nothing
    /// </summary>
    /// <param name="a">First useless parameter</param>
    /// <param name="b">Second useless parameter</param>
    /// <returns>zero</returns>
    public int Foo(int a, int b)
    {
        return 0;
    }

Which gives very nice IntelliSense hint window:

enter image description here

What, if any, is the equivalent in Visual C++ or (even better) a solution that would work in other IDEs like XCode or Eclipse?

Update

I found this similar question, but @edtheprogrammerguy's answer has good references so I'll leave the questino here here. Also, SO won't let me delete my question.

Update the Second

A lot of the C# XML comments (<summary>, for instance) work out of the box. It'd be nice if the /// comment automatically inserted the required summary, param and returns tags, but I imagine that it'd be pretty easy to implement with a new code snippet.

Update the third

Here's a code snippet that inserts the header. It doesn't scan the method parameter list, but it's a nice start. Save to Documents\Visual Studio 2012\Code Snippets\Visual C++\My Code Snippets as anything with a .snippet extension, restart VS, and activate by typing summ + TAB above a method.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>SnippetFile1</Title>
      <Author>dlively</Author>
      <Description>Insert a summary/param/return header for a method</Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>summ</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>summary_text</ID>
          <ToolTip>summary_text</ToolTip>
          <Default>Insert description of method</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>returns_text</ID>
          <ToolTip>returns_text</ToolTip>
          <Default>Description of return value</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>parameter_name</ID>
          <ToolTip>parameter_name</ToolTip>
          <Default>Name of the parameter</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>parameter_description</ID>
          <ToolTip>parameter_description</ToolTip>
          <Default>Description</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="cpp" Kind="method decl"><![CDATA[/// <summary>
/// $summary_text$
/// </summary>
/// <param name="$parameter_name$">$parameter_description$</param>
/// <returns>$returns_text$</returns>]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Also, see the very nice Code Snippet Designer VS extension which makes creating these a breeze.

like image 324
3Dave Avatar asked Dec 07 '13 19:12

3Dave


People also ask

What is IntelliSense in VC?

IntelliSense is a code-completion aid that includes a number of features: List Members, Parameter Info, Quick Info, and Complete Word. These features help you to learn more about the code you're using, keep track of the parameters you're typing, and add calls to properties and methods with only a few keystrokes.

Does Visual Studio have IntelliSense?

Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box. VS Code supports word based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.

How do I enable IntelliSense in C++?

You can enable or disable particular IntelliSense features in the Options dialog box, under Text Editor > C/C++ > Advanced. To configure IntelliSense for single files that aren't part of a project, look for the IntelliSense and browsing for non-project files section.

What is the purpose of IntelliSense in Java programming?

Over time, IntelliSense determines which variable or function the user most likely needs. IntelliSense also displays a short description of a function in the pop-up window—depending on the amount of documentation in the function's source code.


2 Answers

Regarding automatically inserting comment tags by typing ///, I wrote an extension - CppTripleSlash that you might find useful.

like image 144
tcb Avatar answered Oct 07 '22 13:10

tcb


It is for producing documentation from the source files. The /doc compiler option will cause it to generate an .xdc file which can be turned into an .xml documentation file. VC++ is not as nice about Intellisense as C# is.

References:

http://msdn.microsoft.com/en-us/library/ms177227.aspx

http://msdn.microsoft.com/en-us/library/ms173501.aspx

like image 3
edtheprogrammerguy Avatar answered Oct 07 '22 13:10

edtheprogrammerguy