class ViewController: UIViewController {
func raise(base: Int, exp: Int) -> Int {
if (exp == 0) {
return 1
}
else {
return base * raise(base, exp: exp - 1)
}
}
var check = raise(2, exp: 4) // error here
print(check)
}
我对编码和学习递归非常新颖。我只是想调用的函数raise
,看看它是如何工作的,但我得到这个错误:ViewController中的函数“调用中的额外参数”
extra argument in call
有人能告诉我为什么我收到此错误?谢谢。
我使用的是Swift 2.0,当我使用你的代码时它不会给我任何错误。 – Nishant
在旧版本的Swift中,调用将是'var check = raise(2,4)'。 –
@Nishant因为你使用操场而没事吗?尝试在项目中。 –