dsbgltg159136540 2012-04-12 17:33
浏览 95
已采纳

当go函数声明中的参数旁边时,“…”是什么意思?

I was going through some code written in Google's Go language, and I came across this:

func Statusln(a ...interface{})
func Statusf(format string, a ...interface{})

I don't understand what the ... means. Does anybody know?

  • 写回答

3条回答 默认 最新

  • dongying7847 2012-04-12 17:41
    关注

    It means that you can call Statusln with a variable number of arguments. For example, calling this function with:

    Statusln("hello", "world", 42)
    

    Will assign the parameter a the following value:

    a := []interface{}{"hello", "world", 42}
    

    So, you can iterate over this slice a and process all parameters, no matter how many there are. A good and popular use-case for variadic arguments is for example fmt.Printf() which takes a format string and a variable number of arguments which will be formatted according to the format string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据