1
0
Fork 0
pr3-ws202627/go/02-next-level/02-methoden.go

24 lines
378 B
Go

package main
import "fmt"
type Counter struct {
value int
}
func (c Counter /** value reciever **/) toString() string {
return fmt.Sprintf("Counter Value: %d", c.value)
}
func (c *Counter /**Pointer reciever**/) Increment() {
fmt.Printf("Inside Increment: %p\n", c)
c.value = c.value + 1
}
func main() {
c := Counter{}
fmt.Println(c)
c.Increment()
fmt.Println(c)
}