1

我已经使用渠道进行交流..

   b := make([]int,0)  //This is the slice I have created.

我正在将值附加到切片,并且我想将存储在 b 中的最终切片传输给另一个函数。我已经使用了这段代码。

   slic := make(chan int)
   go func() { slic <- input()} ()
   slice := <-slic
   fmt.Println(slice)

我收到此错误:“不能在返回参数中使用 b (type []int) 作为 int 类型。”

4

1 回答 1

3

将您的 chan 更改为:

make(chan []int)

或者选择您的 []int 的索引以发送到您的chan int.

无论哪种方式int[]int都是不同的类型,就像chan intchan []int一样。

于 2013-07-12T17:13:17.500 回答