
struct Set { var player1Games: Int var player2Games: Int init() { self.player1Games = 0 self.player2Games = 0 } func increasePlayer1Gamescore () { player1Games++ // error: Unary operator '++' cannot be applIEd to an operand of type 'Int' } func increasePlayer2Gamescore () { player2Games++ // error: Unary operator '++' cannot be applIEd to an operand of type 'Int' }} 错误消息有点误导.你需要做的是在func之前添加变异来指定它将结构为 modify: struct MySet { var player1Games: Int var player2Games: Int init() { self.player1Games = 0 self.player2Games = 0 } mutating func increasePlayer1Gamescore() { player1Games++ } mutating func increasePlayer2Gamescore() { player2Games++ }} 注意:Set是Swift中的一个类型,我建议为你的struct使用不同的名称.
总结以上是内存溢出为你收集整理的swift – 一元运算符不能应用于Int类型的 *** 作数全部内容,希望文章能够帮你解决swift – 一元运算符不能应用于Int类型的 *** 作数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)