Table of content
WholeTomato

Implement Interface / Virtual Methods

Quickly generate method stubs for methods of an interface or virtual methods of a base class  in C++ or C#. Access this feature from a refactoring menu when on the class you wish to implement. Inserted stubs contain code taken from a VA Snippet, typically code to throw an unimplemented exception and remind a developer to implement functionality.

Implement Interface / Virtual Methods descends into inherited classes, so methods from base classes of multiple depths can be implemented.

Access

Open the Quick Action and Refactoring menu (Shift+Alt+Q) from a class that is derived from a base class. Select "Implement Virtual Methods".

Select methods to implement. Methods already implemented are unavailable.

Methods are implemented using a language-dependent VA Snippet, Create from Usage.

Check / uncheck all methods by right clicking on the method.

Implementing Interfaces

If you implement methods of an interface class, all methods are implemented without an intervening dialog.

If a base class has pure virtual methods, and is therefore an interface, the dialog to select methods opens with the pure virtual methods checked, and non-pure virtual methods unchecked.

In a scenario with pure virtual methods, only the pure virtual methods are checked by default.

Multiple Inheritance

To implement methods from more than one inherited class or interface, invoke Implement Interface / Virtual Methods from the current class name, not from an individual interface or base class.

To implement methods from a single inherited class or interface, invoke Implement Interface / Virtual Methods from the name of a base class, not from the current class name.

Complex Scenarios

In a mixed scenario of multiple inheritance, with abstract and concrete classes, Visual Assist lets you select from a list in which only the interface methods are selected by default.

Filtering

If the list of methods to implement/override is long, use filtering to reduce its size. 

Filtering does not affect the states of checked entries so you can filter repeatedly to find a disparate set of methods.

As possible in other dialogs of Visual Assist, use multiple strings, negative filtering, and dot filtering to reduce the size of the list.

If you want to search names and parameter lists, disable the option to filter by name only.

Sorting

By default, methods are sorted in the order they appear in classes. If you wish methods within each class to be sorted by name, enable the respective sort option.

Keyword to Generated C++ Methods

In C++, Code Generation provides you with an option to include the virtual and/or override keyword in methods generated by Implement Interface / Virtual Methods.

Virtual

In C++, use the "virtual" keyword when implementing an interface or overriding virtual base methods.

Override

In C++, use the "override" keyword when implementing an interface or overriding virtual base methods.

You can append "override" to a virtual function declaration to make the compiler override a virtual method inherited from a base class. If the virtual method does not exist in the base class or has a different signature, the compiler raises an error and the compilation fails.

You can insert the "override" keyword on the Code Generation settings in the Options dialog for Visual Assist.

Virtual and Override

In C++, you can also select "virtual and override" to use both keywords.

Default Method Body

Edit the language-dependent VA Snippet for Create From Usage Method Body to change the default method body created by Implement Interface / Virtual Methods.

The following is the default VA Snippet for Create From Usage Method Body in C++.