Move方法体里这么写的同学,麻烦解释一下,谢谢。
person.Address,address = address,person.Address
Move方法体里这么写的同学,麻烦解释一下,谢谢。
person.Address,address = address,person.Address
Move方法体里这么写的同学,麻烦解释一下,谢谢。
2019-11-02
package main import "fmt" type Person struct { Name string Gender string Age uint8 Address string // 结构体里加个属性 } // 这里加个Move方法 func (person *Person) Move(newAddress string) string{ oldAddress:= person.Address person.Address = newAddress return oldAddress } func main() { p := Person{"Robert", "Male", 33, "Beijing"} oldAddress := p.Move("San Francisco") fmt.Printf("%s moved from %s to %s.\n", p.Name, oldAddress, p.Address) }
举报