Tips and Tricks

Automatically add C++11 override to virtual methods

The C++11 standard has been approved and C++14 is around the corner. These new standards define a lot of interesting language features, one of them being support for the override identifier. You can append “override” to a virtual function declaration and tell the compiler that you want to 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.

blogOverrideExample

Use of override is very useful for detecting errors, at compile time, caused by typos and bad copy-pastes.

Visual Studio has supported override since Visual Studio 2010, and so has Visual Assist. But if you want Visual Assist to insert “override” automatically—when using the code generation feature Implement Virtual Methods—you need to tell it via the Windows Registry.

Note: Beginning with Visual Assist build 2042, you can insert “override” automatically via the options dialog of Visual Assist. The following instructions apply to build 2036 and older.

Exit your IDE(s) so Visual Assist does not overwrite your changes, then using the registry editor, navigate to this key:

HKEY_CURRENT_USER\Software\Whole Tomato\Visual Assist X\<IDE_SPEC>

Change the value of UseOverrideKeywordInImplementInterface from 00 to 01.

blogOverrideRegistry

Restart you IDE, and from now on, Visual Assist will append override to the signatures of your virtual methods.

This article was contributed by Manuel Maier, student at Hochschule der Medien Stuttgart, Germany.

2 Comments

Leave a Reply

%d