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