亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 Go 中的另一個嵌套結構變量訪問結構的變量

從 Go 中的另一個嵌套結構變量訪問結構的變量

Go
拉莫斯之舞 2023-06-05 19:42:47
給出了我寫的 2 個結構。type DNSPacket struct {    header      DNSHeader.DNSHeader    questions   []DNSQuestion.DNSQuestion    answers     []DNSRecord.DNSRecord    authorities []DNSRecord.DNSRecord    resources   []DNSRecord.DNSRecord}type DNSHeader struct {    id uint16 //16bits    recursion_desired    bool  // 1 bit    truncated_message    bool  // 1 bit    authoritative_answer bool  // 1 bit    opcode               uint8 // 4 bits    response             bool  // 1 bit    rescode             ResultCode // 4 bits    checking_disabled   bool       // 1 bit    authed_data         bool       // 1 bit    z                   bool       // 1 bit    recursion_available bool       // 1 bit    questions             uint16 // 16 bits    answers               uint16 // 16 bits    authoritative_entries uint16 // 16 bits    resource_entries      uint16 // 16 bits} // total 96 bits現在,當我調用results.header.questionswhere results is a type DNSPacket variable 時,我得到一個[go] result.header.questions undefined (cannot refer to unexported field or method questions)錯誤。我究竟做錯了什么?有解決方法嗎?
查看完整描述

1 回答

?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

這里有一些問題:

  1. 您的兩個結構的字段都不會導出到包含它們的包之外,因為它們以小寫字母開頭。如果要訪問包外的字段,它們必須以大寫字母開頭。

  2. 以小寫字母命名您的包,例如dnsheader, not?DNSHeader。

查看完整回答
反對 回復 2023-06-05
  • 1 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號