forked from steger/pr3-ws202627
24 lines
378 B
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)
|
|
}
|