按引用返回的切片为空:
package main
import "fmt"
func GetItems(items *[]string) {
list := make([]string, 0)
list = append(list, "ok")
items = &list
}
func main() {
var items []string
GetItems(&items)
fmt.Print(len(items)) // expect 1 here, but got 0
}
如何通过引用从函数中返回切片?
蝴蝶刀刀
相关分类