Golang,在函数内部构建错误

时间:2013-10-11 21:02:49

标签: function build compiler-errors go

所以我有一个非常令人沮丧的构建错误,我一直盯着过去一两个小时。它涉及我的链表程序中的一个功能。当它们明显在里面时它认为我在函数之外有声明,并且认为{:}比率是关闭的。我错过了一些非常简单的东西吗?

// 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

构建错误

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

我感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:4)

看起来这是第175行的错,应该是

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

注意我删除了int

相关问题