forked from steger/pr3-ws202526
25 lines
315 B
Go
25 lines
315 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type Counter struct {
|
|
value int
|
|
}
|
|
|
|
// pointer receiver
|
|
func (c *Counter) Increment() {
|
|
c.value++
|
|
}
|
|
|
|
// value receiver
|
|
func (c Counter) String() string {
|
|
return fmt.Sprintf("Counter value: %d", c.value)
|
|
}
|
|
|
|
func main() {
|
|
c := Counter{}
|
|
fmt.Println(c)
|
|
c.Increment()
|
|
fmt.Println(c)
|
|
}
|