如何在多个地方更改功能声明 [英] How to change function declaration in multiple places
本文介绍了如何在多个地方更改功能声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个函数add(int a,int b)
现在我添加了add(int a,int b,int c)
我称这个功能超过50个。
如何在所有地方改变同一时间。
谢谢
Hi
I have a function add(int a, int b)
now i added add( int a , int b, int c)
I called this function in more then 50 pleaces.
How to change in all the places at a same time.
Thank you
推荐答案
你真的不能这样做 - 因为没有人知道应该添加什么值或变量!
如果现有代码是
You can't really do that - because nobody knows what value or variable should be added in!
If the existing code is
myClass.add(index, count);
它应该变成:
Should it become:
myClass.add(index, count, numberOfBananas);
或
Or
myClass.add(index, count, 0);
这完全取决于代码调用方法的背景。
但是......最简单的方法可能是更改新方法的定义:
It all depends on the context of why your code is calling the method.
But...the easiest way may be to change the definition of your "new" method:
public int add(int a, int b, int c = 0)
{
return a + b + c;
}
在这种情况下,您的外部代码根本不需要更改,因为除非指定,否则最终值将默认为零。
In which case your external code will need no changes at all as the final value will be defaulted to zero unless it is specified.
这篇关于如何在多个地方更改功能声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文