CLion 2021.1 Help

Change signature

The Change Signature refactoring combines several different modifications that can be applied to a function signature. You can use this refactoring to:

  • change the function name and return type

  • add, remove, and reorder parameters

When changing a function signature, CLion searches for all usages of the function and updates all the calls, implementations, and override replacements of the function that can be safely modified to reflect the change.

Change a function signature

  1. Place the caret at the function you want to refactor.

  2. Press Ctrl+F6 or select Refactor | Change Signature from the main menu or the context menu.

  3. In the Change Signature dialog, make the necessary changes to the function signature:

    • Change the function name in the Name field.

    • Change the function return type in the Return type field.

    • Manage the function parameters using the table and the Add/ Remove/ Move up/ Move down buttons.

      When adding a parameter, specify the new parameter's properties in the corresponding row: Type, Name, and Default value.

      The Default value field sets the type value to be used as an argument to the usages. If you leave this field empty, CLion will use the default type value (for example, 0 for numerical and nullptr for pointers).

      Change signature refactoring

Examples

BeforeAfter
//Initial function signature int exFunction2(int a, int b) { int x = a+b; return x; }; int main() { int a = 0, b = 1; int x = exFunction2(a, b); return 0; }
//Name changed, the third parameter introduced int exFunction3(int a, int b, int c) { int x = a+b; return x; }; int main() { int a = 0, b = 1; int x = exFunction3(a, b, 0); //default value '0' added return 0; }
BeforeAfter
//This function will be turned into a block float multiply (int x, int y) { return x * y; } int main (int argc, const char * argv[]) { @autoreleasepool { float result; result = multiply( 10, 20 ); } return 0; }
int main (int argc, const char * argv[]) { @autoreleasepool { float result; result = //a block was generated ^float(int x, int y) { return x * y; }(10, 20); } return 0; }
BeforeAfter
# This function will be renamed def fibonacci( n ): a, b = 0, 1 while b < n: print( b ) a, b = b, a+b n = int(input("n = ")) fibonacci( n )
# Function with the new name def fibonacci_numbers( n ): a, b = 0, 1 while b < n: print( b ) a, b = b, a+b n = int(input("n = ")) fibonacci_numbers( n )
BeforeAfter
//This function wil be renamed //and a default parameter will be added function result() { } function show_result() { alert('Result: ' + result()); }
//Function with a new name and default parameter function generate_result(input = 100) { } function show_result() { alert('Result: ' + generate_result()); }

Last modified: 12 May 2021