go pointer

go pointer

package main



import "fmt"



type Mutatable struct {

    a int

    b int

}



func (m Mutatable) StayTheSame() {

    m.a = 5

    m.b = 7

}



func (m *Mutatable) Mutate() {

    m.a = 5

    m.b = 7

}



func main() {

    m := &Mutatable{0, 0}

    fmt.Println(m)

    m.StayTheSame()

    fmt.Println(m)

    m.Mutate()

    fmt.Println(m)

}

&{0 0}

&{0 0}

&{5 7}

你可能感兴趣的:(poi)