diff options
| author | Andrew Gerrand <adg@golang.org> | 2016-01-05 16:43:40 +1100 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2016-01-07 02:11:17 +0000 |
| commit | fe12a66e2eb3cf260ea027cfaf5a6b2c9194c7dc (patch) | |
| tree | 279ab263b6b17f3b239a35924c65fbcf944dd37e /content/methods/indirection-values.go | |
| parent | 4e6c47c1628134f8c4a5fd58b7b61ac30a25b632 (diff) | |
| download | golang-id-tour-fe12a66e2eb3cf260ea027cfaf5a6b2c9194c7dc.tar.xz | |
content: expand discussion of methods
Fixes golang/go#13818
Change-Id: I22817c0c3bfa3d7e5a769f239a2521c293112a43
Reviewed-on: https://go-review.googlesource.com/18246
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'content/methods/indirection-values.go')
| -rw-r--r-- | content/methods/indirection-values.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/content/methods/indirection-values.go b/content/methods/indirection-values.go new file mode 100644 index 0000000..04e022b --- /dev/null +++ b/content/methods/indirection-values.go @@ -0,0 +1,30 @@ +// +build OMIT + +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 AbsFunc(v Vertex) float64 { + return math.Sqrt(v.X*v.X + v.Y*v.Y) +} + +func main() { + v := Vertex{3, 4} + fmt.Println(v.Abs()) + fmt.Println(AbsFunc(v)) + + p := &Vertex{4, 3} + fmt.Println(p.Abs()) + fmt.Println(AbsFunc(*p)) +} |
