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:
- With the class in question having the focus, invoke the
- Press Ctrl+O.
- On the main menu, choose .
- Right-click the editor, choose Generate on the context menu, or press Alt+Insert, and choose Override functions.
command in one of the following ways: - 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.
- Select one or more methods to override.
- If necessary, select the following options:
- Show non-virtual functions
- Insert "override" attribute
- Having generated the overriding function, create the required source code. Note the 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" ( ), 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.
}
Last modified: 15 December 2017