doqvzh345334 2015-03-04 21:36
浏览 33
已采纳

在Golang中接受地图参数

I have a simple function which tests whether a string is an integer

func testInt(str string, m map[bool]) int {
    _,e := strconv.ParseInt(str, 0, 64);
    return m[nil == e] * 7;
}

where the map being passed contains m[true] = 1, m[false] = 0. However, when I attempt to run this Go complains

1: syntax error: unexpected )

Either I cannot pass maps around as parameters in this way or else I am doing this entirely wrong. In any case, I would much appreciate some help

  • 写回答

1条回答 默认 最新

  • donglefu6195 2015-03-04 21:44
    关注

    A map maps keys to values, using the syntax

    map[KeyType]ValueType
    

    (see https://blog.golang.org/go-maps-in-action)

    In your function, you have not specified a ValueType, causing this syntax error. It looks like you want a map[bool]int.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部