doqvzh345334 2015-03-05 05: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-05 05: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.

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

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用