Исходники и презентации
This commit is contained in:
24
lessons/structs/recursive_receiver/main.go
Normal file
24
lessons/structs/recursive_receiver/main.go
Normal file
@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type account struct {
|
||||
balance int
|
||||
}
|
||||
|
||||
type client struct {
|
||||
account *account
|
||||
}
|
||||
|
||||
func (c client) add(value int) {
|
||||
c.account.balance += value
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := client{
|
||||
account: &account{},
|
||||
}
|
||||
|
||||
c.add(100)
|
||||
fmt.Println(c.account.balance)
|
||||
}
|
||||
Reference in New Issue
Block a user