是否可以从指向字符串的指针获取字符串值?
我正在使用 goopt 包 来处理标志解析,并且该包仅返回 *string。我想使用这些值来调用地图中的函数。
var strPointer = new(string)
*strPointer = "string"
functions := map[string]func() {
"string": func(){
fmt.Println("works")
},
}
//Do something to get the string value
functions[strPointerValue]()
回报
./prog.go:17:14: cannot use strPointer (type *string)
as type string in map index
原文由 Jared Meyering 发布,翻译遵循 CC BY-SA 4.0 许可协议
取消引用指针: