【发布时间】:2017-07-19 11:16:54
【问题描述】:
当我阅读有关 swift 类型推断的信息时,我开始知道 swift 足够聪明,可以了解数据类型
就像我写这个程序的时候
var v3 = 2+2.5
print("the result is \(v3)")
然后我看到输出
the result is 4.5
但是当我写这个程序时
var v1 = 2.5
var v2 = 2
var v3:Double = v1 + v2
print("the result is \(v3)")
然后它给了我这个错误
ERROR at line 7, col 20: binary operator '+' cannot be applied to operands of type 'Double' and 'Int'
var v3:Double = v1 + v2
~~ ^ ~~
NOTE at line 7, col 20: expected an argument list of type '(Double, Double)'
var v3:Double = v1 + v2
谁能解释一下这里发生了什么
我已经在 IBM 沙盒上完成了这个程序
【问题讨论】:
标签: swift swift3 type-inference