下面这段代码如何理解

type Node struct {
    _ int
    id int
}

上面这段代码不知如何理解,这个结构体如何初始化?

阅读 1.4k
1 个回答

code:

package main

import "fmt"

type Node struct {
    _  int
    id int
}

func main() {
    n := Node{
        id: 1,
    }
    fmt.Println(n)
}

这个补位字段,它不能读取,不能赋值,作用就是占个位置。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题