dragon8837
2014-02-12 05:52
浏览 310
已采纳

在golang中将数组作为参数传递

Why does this not work?

package main

import "fmt"

type name struct {
    X string
}

func main() {
    var a [3]name
    a[0] = name{"Abbed"}
    a[1] = name{"Ahmad"}
    a[2] = name{"Ghassan"}

    nameReader(a)
} 

func nameReader(array []name) {
    for i := 0; i < len(array); i++ {
        fmt.Println(array[i].X)
    }
}

Error:

.\structtest.go:15: cannot use a (type [3]name) as type []name in function argument

6条回答 默认 最新

相关推荐 更多相似问题