CLion 2016.3 Help

Implementing Functions

On this page:

Introduction

If a class has a base class with pure virtual functions, it can't be instantiated unless it implements those functions. CLion creates stubs of the implemented functions, with the default return values for the primitive types, and null values for the objects.

Implementing functions

To implement function , follow these steps:

  1. Do one of the following:
    • On the main menu, choose Code | Implement function.
    • Press Ctrl+I
    • Right-click the editor, choose Generate on the context menu, or press Alt+Insert, and choose Implement functions.

    The Select functions to implement dialog appears, displaying the list of classes and interfaces with the functions that can be implemented.

    Note, that in case when 1) more than one class is visible at the desired position and 2) the caret is placed outside of any of that classes implementations, the IDE prompts you to choose a destination class:

    /help/img/idea/2016.3/cl_ImplementChooseDestination.png
    Otherwise, when the caret was placed inside a class the generated function will be placed at the caret position by default.

  2. Select one or more functions to implement. For multiple selection, use Ctrl and Shift keys.
    /help/img/idea/2016.3/cl_implement.png
  3. Click OK.

Changing function body

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

For example, consider the following file template:

#if ($DEFAULT_RETURN_VALUE == "result") $RETURN_TYPE result; return result;#elseif ($RETURN_TYPE != "void") return $DEFAULT_RETURN_VALUE;#end

This template expands into the following code:

int Calendar::getMonth() { return 0;/// TODO (wombat, 1/22/2015):To change the body of an implemented function, use File | Settings - Editor - File and Code Templates. } void Calendar::setMonth(int month) { /// TODO (wombat, 1/22/2015):To change the body of an implemented function, use File | Settings - Editor - File and Code Templates. }

See Also

Last modified: 29 March 2017