CLion 2016.3 Help

Overriding Functions

On this page:

Overview

You can override any function of a parent class, using the code generation facility. CLion creates a stub that contains a call to the function of the superclass, leaving the developer with the task of providing some meaningful source code.

Overriding functions

To override functions, follow these steps:

  1. With the class in question having the focus, invoke the Override function command in one of the following ways:
    • Press Ctrl+O.
    • On the main menu, choose Code | Override function.
    • Right-click the editor, choose Generate on the context menu, or press Alt+Insert, and choose Override functions.
  2. Select functions that can be overridden from the Select functions to override dialog box. The list of functions does not include the methods that are already overridden, or cannot be accessed from the current subclass.
    /help/img/idea/cl_override.png
  3. Select one or more methods to override.
  4. If necessary, select the following options:
    • Show non-virtual functions
    • Insert "override" attribute
  5. Having generated the overriding function, create the required source code. Note the gutterIconOverriding.GIF icon that marks the overriding method in the left gutter. Use this icon to view the name of the base class, and navigate to the overridden method.

Changing function body

File template responsible for overriding a function (Overridden method body) accepts predefined template variables from "File Header" (File | Settings - Editor - File and Code Templates - Code - File Header ), e.g. ${USER}, ${DATE}, etc.

For example, consider the following file template:

#if ($CALL_SUPER != "")#if ($RETURN_TYPE != "void")return#end $CALL_SUPER;#end // TODO ($USER, $DATE):To change the function body, use Settings - Editor - File and Code Templates.

The template expands into the following code:

int Calendar::getYear() { return 0;/// TODO (wombat, 1/22/2015):To change the function body, use Settings - Editor - File and Code Templates. }

See Also

Last modified: 22 November 2016