ReSharper 2016.3 Help

Coding Assistance in C++

Most of ReSharper's coding assistance features are also supported in C++. You can find the detailed information on these features in the corresponding topics of the Coding Assistance section. In the main topic of the section, you can also find the feature matrix and check what exactly is supported in C++.

In this topic, you can find some examples of using coding assistance features in C++:

Code completion

Automatic and basic completion

In C++ files, you can use automatic and basic (Ctrl+Space) completion when writing your code. For example, you can quickly add enum members taken from a different namespace:

Automatic completion in C++

Dot/arrow completion helpers

When you call a method, you can always type a dot (.) or an arrow (->) and get all available methods in the completion list. The methods that do not match ./-> are displayed in grey. If you choose such method, the ./-> will be corrected automatically:

Replacing dot with arrow in completion

Generative completion

Generative completion suggestion are also available. For example, when you call a member function declaration on the object...

Generative completion in C++

ReSharper generates the following function:

Generative completion in C++

Postfix completion

Postfix completion in C++ is very much like C# extension methods. If you type a dot (.) or an arrow (->) after an expression, ReSharper will suggest free functions that would accept that expression as the first parameter. When you accept the suggestion, ReSharper will rewrite your code so that the expression is passed as the first argument:

Postfix templates

Postfix templates, similarly to postfix completion help you transform expressions that you have already typed without jumping backwards. However, instead of looking up for suitable methods, postfix templates let you quickly wrap an expression with the following statements: if, else, while, do, return, switch, foreach.

Syntax highlighting and tooltips

By default, ReSharper provides extended highlighting of C++ syntax with configurable colors. If necessary, you can disable it on the Code Editing | C++ | Inspections page of ReSharper options. There are 20 identifier types that you can highlight differently. You can change colors and fonts at any time in Visual Studio options (Tools | Options | Environment | Fonts and Colors).

Configuring syntax highlighting for C++ identifiers

ReSharper also replaces Visual Studio tooltips for code elements with its own tooltips, which have highlighted syntax, display method and field signatures, formatted XML and Doxygen comments:

Code element tooltip in C++

If necessary, you can disable ReSharper tooltips by clearing the Replace Visual Studio tooltips check box on the Environment | Editor | Editor Appearance page of ReSharper options. Note also that ReSharper tooltips are only available if the syntax highlighting is enabled.

Context Actions

ReSharper provides a set of context actions that target C++ code. You can find the full list of these actions in the Code Editing | C++ | Context actions page of ReSharper options. If necessary, you can also disable some of the actions using this page.

As soon as a context action becomes available for the current caret position, ReSharper displays the corresponding action indicator /help/img/dotnet/2016.3/ThemedIcon.ContextAction.Screen.[Gray].png to the left of the caret. Sometimes, however, ReSharper provides several contextually available features for the current caret position. In this case, the action indicator corresponding to the action with the highest priority is shown, and all other actions only appear when you expand the action list by clicking on the action indicator or pressing Alt+Enter Context actions have the lowest priority, therefore, they often appear in the bottom of the action list:

Here are some examples of context actions for C++:

Generate missing case statements

Instead of manually writing all case statements when switching over an enum, you can use the context action that generates all missing case statements:

Generating missing case statements in C++
All you have to do then is to write the required logic for each statement.
Generating missing case statements in C++

Merge nested 'if' statements

ReSharper helps you merge nested 'if' statements with the context action:

Merging nested 'if' statements in C++

Generate implementation

ReSharper helps you automatically create a stub implementation of a function or a method. You can always generate an inline implementation and, if the function is defined in a header file and there is the corresponding source file, you can generate the implementation in the source file.

Generating implementation for a function

Move implementation out of class scope

ReSharper helps you move the implementation of a function or a method from a header to the corresponding source file if it exists. After applying this context action the definition is left in its original place and the implementation is moved to the source file. The editor context is switched to the source file as well.

Moving implementation out of class scope to the source file

You can also use the context action to move all implementations in the current selection.

Document

With this context action, you can generate documentation comments for C++ symbols. If necessary, you can customize the comment stub by editing the doc live template that ReSharper uses for the generation.

Highlighting paired items

ReSharper highlights various matching items when you set the caret to one item of the pair:

  • Matching delimiters ((), [], {}, and <>)
  • Matching macros, for example, BEGIN_NAMESPACE / END_NAMESPACE
  • Matching format specifier and argument in printf and boost::format
Last modified: 12 October 2017

See Also