筆記一 運算子重定義
阿新 • • 發佈:2018-12-30
struct CenterPointer{
var x=0, y=0
}
func + (left:CenterPointer, right:CenterPointer) -> CenterPointer{
return CenterPointer(x:left.x+right.y, y:left.y+right.y)
}
//
//let pointer1 = CenterPointer(x:2, y:3)
//let pointer2 = CenterPointer(x:4, y:5)
//let pointer3 = pointer1 + pointer2
//
//
//
//func == (left:CenterPointer, right:CenterPointer) -> Bool {
// return (left.x == right.x) && (left.y == right.y)
//}
//
//func != (left:CenterPointer, right:CenterPointer) -> Bool {
// return !(left == right)
//}
//
//
//print(pointer1 == pointer1)
//
//
func += (inout left:CenterPointer, right:CenterPointer){
left = left + right
}
var pointer1 = CenterPointer
var pointer2 = CenterPointer(x:4, y:5)
pointer1+=pointer2