3
我在函數中定義了一個結構,無論我調用函數多少次,結構定義看起來總是第一次調用函數。函數中定義的結構
代碼:
var g = 0
func f() {
struct InnerStruct{
static var attr:Int = g
}
println("static attr value is \(InnerStruct.attr), g is \(g)")
}
f()
g++
f()
g++
f()
結果是:
static attr value is 0, g is 0
static attr value is 0, g is 1
static attr value is 0, g is 2
Program ended with exit code: 0
我不熟悉的迅速,任何機構可以解釋,爲什麼?
THX,我覺得我得到了答案。 – 6174 2014-09-06 12:09:08