2012년 5월 1일 화요일

struct 와 method


출처: http://tour.golang.org/#49


class 는 어디가고, struct 와 method 만 남았다.

method receiver 라는 용어가 등장했다. (v *Vertex)





package main


import (
"fmt"
"math"
)


type Vertex struct {
X, Y float64
}


func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}


func main() {
v := &Vertex{3, 4}
fmt.Println(v.Abs())
}




D:\DEV\PP\work_4\src>go run hello67.go
5