Google Go Error - Unable to Type

In my Go code, I want to create an array of custom data types. I'm calling

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

and I get an error:

 cannot make type *BlockData 

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

What should I do to fix this error?

+6
source share
2 answers

make() used to create slices, maps, and channels. The type name must have [] before this when creating the fragment.

Use this to make a piece of pointers in BlockData.

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

Read more in Go to language specification .

+10
source

Creating Fragments, Maps, and Channels

For instance,

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

Conclusion:

 4 [<nil> <nil> <nil> <nil>] 
+1
source

Source: https://habr.com/ru/post/903439/


All Articles