下面的代码给出了一个错误,因为它试图调用类的方法而不是全局函数:
func a(i: Int) -> Int {
return i + 10
}
class B {
func a(s: String) -> String {
return s + "bbb"
}
func b() {
print(a(100))
// Error (Cannot convert value of type 'Int' to expected argument type 'String')
}
}
Run Code Online (Sandbox Code Playgroud)