CLion 2025.2 Help

更改签名

更改签名重构结合了几种可以应用于函数签名的不同修改。 您可以使用此重构来:

  • 更改函数名称和返回类型

  • 添加、移除和重新排序参数

在更改函数签名时,CLion 会搜索该函数的所有用法,并更新所有可以安全修改的调用、实现和覆盖替换,以反映更改。

添加参数

  1. 点击 return 值,该值已用红色高亮显示。

  2. Alt+Enter 并选择 创建parameter '<parameter_name>'

  3. 更改签名 对话框中,调整参数设置或接受建议的设置。

  4. 点击 重构(R)

更改函数签名

  1. 将插入符号放置在您想要重构的函数上。

  2. Ctrl+F6 或从主菜单或上下文菜单中选择 重构 | 更改签名

  3. 更改签名 对话框中,对函数签名进行必要的更改。

    • 名称 字段中更改函数名称。

    • 返回类型 字段中更改函数返回类型。

    • 使用表格和 Add/移除/向上移动/向下移动 按钮管理函数参数。

      添加参数时,在相应的行中指定新参数的属性: Type名称默认值

      默认值 字段设置用作用法参数的类型值。 如果您将此字段留空,CLion 将使用默认类型值(例如,数字使用 0 ,指针使用 nullptr)。

      更改签名对话框
    • 您还可以使用相应的复选框使函数成为 constconstexprnoexcept

示例

之前

之后

//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; }

之前

之后

//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; }

之前

之后

# 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 )

之前

之后

//This function will 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()); }
最后修改日期: 2025年 9月 26日