Advertisement
khangnguyen

Go methods

May 26th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.38 KB | None | 0 0
  1. type Vertex struct {
  2.     X, Y float64
  3. }
  4.  
  5. func (v *Vertex) Abs() float64 {
  6.     return math.Sqrt(v.X*v.X + v.Y*v.Y)
  7. }
  8.  
  9. func main() {
  10.     v := &Vertex{3, 4}
  11.     fmt.Println(v.Abs())
  12. }
  13.  
  14.  
  15.  
  16.  
  17. type Vertex struct {
  18.     X, Y float64
  19. }
  20.  
  21. func (v *Vertex) Abs() float64 {
  22.     return math.Sqrt(v.X*v.X + v.Y*v.Y)
  23. }
  24.  
  25. func main() {
  26.     v := Vertex{3, 4}
  27.     fmt.Println(v.Abs())
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement