【发布时间】:2014-12-17 02:30:15
【问题描述】:
是否可以从指向字符串的指针中获取字符串值?
我正在使用goopt package 处理标志解析,并且包仅返回 *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
【问题讨论】:
标签: string pointers go type-conversion