Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.64 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. type basic_method interface{
  8.     // sum() int
  9.     // total() int
  10.     add()
  11. }
  12.  
  13. type ele struct{
  14.     elements *[]int
  15. }
  16.  
  17. // func (e ele) sum() int{
  18. //  sum := 0
  19. //  for _, v := range e.elements{
  20. //      sum += v
  21. //  }
  22. //  return sum
  23. // }
  24.  
  25. // func (e ele) total() int{
  26. //  t := 0
  27. //  for i:=0;i<len(e.elements); i++{
  28. //      t += 1
  29. //  }
  30. //  return t
  31. // }
  32.  
  33.  
  34. func (e ele) add(){
  35.     e.elements = append(e.elements, 1)
  36.     fmt.Println(e.elements)
  37. }
  38.  
  39.  
  40. func measure(b basic_method){
  41.     b.add()
  42.     b.add()
  43.     b.add()
  44.     // fmt.Println(b.total())
  45.     // fmt.Println(b.sum())
  46. }
  47.  
  48. func main(){
  49.     e := new(ele)
  50.     measure(e)
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement