• RSS Feed

Auto Using and Add Include Directives

When you type a symbol known to Visual Assist but not within the current file, Visual Assist can insert a directive in your current file to make the symbol known.

Using Directive in C#

Reference a common .NET type, and Visual Assist suggests adding the appropriate using directive. Accept the suggestion and Visual Assist inserts the directive near the top of the current file, without changing the position of the text caret.


Visual Assist suggests directives as you type

Visual Assist suggests directives if it is configured—in the options dialog of Visual Assist—to display listboxes for C#.

Include Directive in C/C++

Hover over an undeclared identifier and choose "Add include" from a refactoring menu (Shift+Alt+Q) to insert the appropriate directive. The directive is inserted after the last #include in your current file, outside of any #ifdef directives. The position of the text caret is unchanged.


Add #include from Quick Refactoring menu (Shift+Alt+Q)

Note: Except for a few system libraries such as MFC and CRT, Visual Assist can only suggest to include headers if it has parsed them. If "Add include" is missing from, or disabled in, a refactoring menu, add the appropriate directory(ies) to your project settings, and manually include the directory somewhere in your project or solution. Once included in one location, Visual Assist can suggest to include the header in other locations.


Lack of "Add #include" is a hint to update directories in project settings

Umbrella Headers in C/C++

In most cases, Visual Assist adds the specific header that contains the definition of a symbol, not an umbrella header that includes it and other related headers. There are a few exceptions for several popular libraries, including Boost and Qt. In these cases, Visual Assist adds the umbrella header.

Note: Except for a few system libraries such as MFC and CRT, Visual Assist can only suggest to include headers if it has parsed them, including the headers for Boost and Qt. Headers for Boost or Qt should be listed in the VC++ Directories of your project, so they are considered stable, and included somewhere in a solution. Once included in one location, Visual Assist can suggest to include the headers in other locations.

Caution in C/C++

Be mindful not to add headers needlessly, since Visual Assist lets you add the header that contains the definition of the symbol, even if you have already included an umbrella header.

Add Include makes the addition of headers convenient. You should rely on compiler errors, and your knowledge of header hierarchy, to decide if a #include is required.