golang
虫来
这个作者很懒,什么都没留下…
展开
-
golang 面向对象
method的语法如下: func (r ReceiverType) funcName(parameters) (results) 下面我们用最开始的例子用method来实现: package main import ( "fmt" "math" ) type Rectangle struct { width, height float64 } type C转载 2013-06-08 20:37:03 · 1255 阅读 · 0 评论 -
golang 函数
函数作为值、类型 在Go中函数也是一种变量,我们可以通过type来定义它,它的类型就是所有拥有相同的参数,相同的返回值的一种类型 type typeName func(input1 inputType1 , input2 inputType2 [, ...]) (result1 resultType1 [, ...]) 函数作为类型到底有什么好处呢?那就是可以把这个类型的函数当做值转载 2013-06-08 20:40:09 · 1136 阅读 · 0 评论 -
golang 函数
(input1 inputType1 , input2 inputType2 [, ...]) (result1 resultType1 [, ...]) 函数作为类型到底有什么好处呢?那就是可以把这个类型的函数当做值来传递,请看下面的例子 package main import "fmt" type testInt func(int) bool // 声明了一个函数类型 func isOdd(integer int) bool { if integer%原创 2013-04-15 23:21:16 · 101 阅读 · 0 评论 -
golang 面向对象
angle struct { width, height float64 } type Circle struct { radius float64 } func (r Rectangle) area() float64 { return r.width*r.height } func (c Circle) area() float64 { return c.radius * c.radius * math.Pi } func ma原创 2013-04-15 23:58:09 · 81 阅读 · 0 评论