jweinst1
4/28/2016 - 4:13 PM

using method with a struct

using method with a struct

package main

import (
	"fmt"
	"runtime"
)

type apple struct {
	count int
}

func (fruit apple) addtocount(amount int) {
	fruit.count += 1
}

func main() {
	tom := apple{count:3}
	tom.addtocount(3)
	fmt.Println(tom)
	runtime.GC()
}