dongwen1935 2013-10-11 21:02
浏览 84
已采纳

Golang,在函数内部生成错误

So I have a really frustrating build error I have been staring at for the past hour or two. It involves one of my functions in my linked list program. It thinks I have statements outside the function when they are clearly inside, and thinks the { : } ratio is off. Am I missing something really simple?

// Index returns the location of element e. If e is not present,
// return 0 and false; otherwise return the location and true.
func (list *linkedList) Index(e AnyType) (int, bool) {
        var index int = 0
        var contain bool = false
        if list.Contains(e) == false {
            return 0, false
        }
        for int i := 0; i < list.count; i++ {    \\175
            list.setCursor(i)
            if list.cursorPtr.item == e {
                index = list.cursorIdx
                contain = true
            }
        }
        return index, contain    \\182
}    \\183

Build errors

./lists.go:175: syntax error: unexpected name, expecting {
./lists.go:182: non-declaration statement outside function body
./lists.go:183: syntax error: unexpected }

I appreciate any help. Thank you.

  • 写回答

1条回答 默认 最新

  • douyun8901 2013-10-11 21:08
    关注

    Looks like it's all line 175's fault, should be

    for i := 0; i < list.count; i++ {
    

    note I removed int

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?