CLion 2024.2 Help

Override functions

You can override any function of a parent class by generating necessary code from a predefined template. 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 in the method's body.

Override a member function of a superclass

  1. On the Code menu, click Override methods Ctrl+O. Alternatively, you can right-click anywhere in the class file, then click Generate Alt+Insert, and select Override methods.

  2. Select the functions to override (hold the Shift or Ctrl key to perform a multi-selection). The list does not include the functions that are already overridden or cannot be accessed from the current subclass.

    Selecting functions to override
  3. Click OK and provide the source code for the function body.

Change the function body

The code template used for overriding functions (Overridden method body) accepts predefined template variables from the File Header include template (such as ${USER}, ${DATE}, and so on).

For example, consider the following code 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/2022):To change the function body, use Settings - Editor - File and Code Templates. }
Last modified: 08 October 2024