【问题标题】:Cannot use type chan []string) as type []chan string?不能使用 type chan []string) 作为 type []chan 字符串?
【发布时间】:2019-05-31 14:45:51
【问题描述】:
package main

import "fmt"

func x(foo []string, cz chan string) {
    for i := range foo {
        cz <- foo[i]
    }
}

func y(foo []string, cz chan string) {
    for i := range foo {
        cz <- foo[i]
    }
}

type cz struct {
    cSlice []chan string
}

func main() {

    var quality []string = make([]string, 2)
    quality[0] = "hello"
    quality[1] = "world"
    //name := []string{"mother", "earth"}

    var channel cz

    for i := range channel.cSlice {
        go x(quality, channel.cSlice[i])
        go y(quality, channel.cSlice[i])
        x, y := <-channel.cSlice[i], <-channel.cSlice[i]
        fmt.Println(x, y)
    }
}

现在什么都没有收到嗯...

更新^

...需要更多文字。

...然后再多一点。好的,还有多少?

我真的不敢相信。 fdsaf asf asfasdfdasfadfd

【问题讨论】:

  • 检查你的函数参数,你要求一个 []chan 字符串,它是一个通道切片,而不是一个 chan [] 字符串。
  • 是的,我搞砸了哈哈。

标签: go channel goroutine


【解决方案1】:
cannot use channel.cSlice (type chan []string) as type []chan string in argument to x
cannot use channel.cSlice (type chan []string) as type []chan string in argument to y

阅读错误信息。

type chan []string

type []chan string

它们是不同的。

游乐场:https://play.golang.org/p/CKhj8DUGTle

【讨论】:

  • 谢谢...但是现在:无效操作:
  • @user10032371
  • 你似乎是对的。我更新了代码,它的工作原理是减去未发送到 func x, y 的“质量”。
猜你喜欢
  • 2013-09-19
  • 2018-05-10
  • 2021-11-16
  • 2020-01-12
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
  • 2017-06-05
  • 1970-01-01
相关资源
最近更新 更多