Google Go 错误 - “无法输入”

发布于 2024-12-20 11:46:06 字数 313 浏览 0 评论 0原文

在我的 Go 代码中,我想创建一个自定义数据类型的数组。我调用

Blocks=make(*BlockData, len(blocks))

并收到错误:

cannot make type *BlockData

我的类 BlockData 包含 uint64、int64、float32、string、[]byte、[]string 和 []*TransactionData 等字段类型。最后一个是指向我的另一个自定义类的指针数组。

我应该怎么做才能修复这个错误?

In my Go code I want to make an array of custom data type. I call

Blocks=make(*BlockData, len(blocks))

and I get error:

cannot make type *BlockData

my class BlockData contains such field types as uint64, int64, float32, string, []byte, []string and []*TransactionData. The last one is an array of pointers to another custom class of mine.

What should I do to fix this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年已逝 2024-12-27 11:46:07

make() 用于创建切片、贴图和通道。制作切片时,类型名称前面必须有 []

使用它来创建指向 BlockData 的指针切片。

Blocks = make([]*BlockData, len(blocks))

请参阅 Go 语言规范了解更多信息。

make() is used to create slices, maps and channels. The type name must have [] before it when making a slice.

Use this to make a slice of pointers to BlockData.

Blocks = make([]*BlockData, len(blocks))

Read more in the Go language specification.

单身狗的梦 2024-12-27 11:46:07

制作切片、贴图和通道

例如,

package main

import "fmt"

type BlockData struct{}

func main() {
    blocks := 4
    Blocks := make([]*BlockData, blocks)
    fmt.Println(len(Blocks), Blocks)
}

输出:

4 [<nil> <nil> <nil> <nil>]

Making slices, maps and channels

For example,

package main

import "fmt"

type BlockData struct{}

func main() {
    blocks := 4
    Blocks := make([]*BlockData, blocks)
    fmt.Println(len(Blocks), Blocks)
}

Output:

4 [<nil> <nil> <nil> <nil>]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文