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?
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.
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>]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With