doumo0206 2017-02-05 10:48
浏览 122
已采纳

要附加的第一个参数必须是slice

I am having trouble calling the append function in Go

type Dog struct {
    color  string
}

type Dogs []Dog

I want to append "Dog" into "Dogs".

I tried doing this

Dogs = append(Dogs, Dog)

But I get this error

First argument to append must be slice; have *Dogs

Sorry, I'm new to Go.

Thanks!

Edit: Also, if I want to check if this Dog contains the color "white", for example. How would I call this?

 if Dog.color.contains("white") { 
    //then append this Dog into Dogs
 }
  • 写回答

2条回答 默认 最新

  • dtziv24262 2017-02-05 10:51
    关注

    Dogs is a type not a variable, you probably meant to:

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

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题