swift operator+()

前端之家收集整理的这篇文章主要介绍了swift operator+()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

class mypoint{

var x:Int =1;

var y:Int =1;

init(#x:Int,#y:Int){

self.x = x;

self.y = y;

}

var description:String{//在这里稍有贪心,做一描述成员get变量

get{

return "x=\(x),y=\(y)";

}

}

}


func +(left:mypoint,right:mypoint)->mypoint{

return mypoint(x: left.x+right.x,y: left.y+right.y);

}


var p1:mypoint =mypoint(x: 1,y:1);

var p2:mypoint =mypoint(x: 2,y:2);

println((p1+p2).description);

原文链接:https://www.f2er.com/swift/326861.html

猜你在找的Swift相关文章