golang 结构体方法 有无指针
package main import "fmt" type Node struct { Val string } func (n Node) Put(str string) { n.Val = str } func (n Node) Pull() string { return n.Val } func main() { n := Node{} n.Put("1") fmt.Println(n.Pull()) } ////// result -> 空
package main import "fmt" type Node struct { Val string } func (n *Node) Put(str string) { n.Val = str } func (n *Node) Pull() string { return n.Val } func main() { n := Node{} n.Put("1") fmt.Println(n.Pull()) } ///////// result -> 1
邮箱: 1090055252@qq.com