We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
与初始化使用关键字“init”类似。析构我们使用关键字“deinit”,并且,只有类(引用类型)才可以使用析构。
init
deinit
struct 老虎机 { static var 银币 = 10_000 static func 赢一场( 赢的游戏币: Int)->Int{ var 赢游戏币 = 赢的游戏币 赢游戏币 = min(赢游戏币 ,银币) 银币 -= 赢游戏币 return 赢游戏币 } static func 输光(输游戏币:Int){ 银币 += 输游戏币 } } class 玩家 { var 游戏币: Int init(游戏币: Int){ self.游戏币 = 游戏币 } func 赢取游戏(赢游戏币: Int){ 游戏币 += 老虎机.赢一场(赢游戏币: 赢游戏币) } deinit{ 老虎机.输光(输游戏币: 游戏币) } }
The text was updated successfully, but these errors were encountered:
miss-shiyi
No branches or pull requests
1. 析构就是在一个实例在被内存释放前调用的一个函数
The text was updated successfully, but these errors were encountered: