<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 一、定義 ![](https://img.kancloud.cn/65/df/65df878d863649a739b90bdc94c04d76_546x113.png) ## 二、匿名字段實例 ~~~ package main import "fmt" // 結構體 type User struct { Id int Name string Age int } type Article struct { // 匿名字段 //這里的User會把我們定義的User結構體放到這里(Article) User title string desc string } func main() { // 順序初始化 s1 :=Article{User{1,"aaa",20},"111","aaaa"} fmt.Println(s1) // 部分初始化 s2 :=Article{User:User{Id: 1},title: "111",desc: "aaaa"} fmt.Println(s2) } ~~~ ## 二、匿名字段同名字段 ~~~ package main import "fmt" // 結構體 type User struct { Id int Name string Age int } type Article struct { // 匿名字段 //這里的User會把我們定義的User結構體放到這里(Article) User title string desc string Name string } func main() { var a Article a.Name = "a1" fmt.Println(a) //默認是就近原則賦值 //如需要賦值上一層,需要顯式調用 a.User.Name = "a2" fmt.Println(a) } ~~~ 結果: {{0 0} a1} {{0 a2 0} a1} ## 三、所有的內置類型和自定義類型都是可以作為匿名字段來使用 ~~~ package main import "fmt" // 結構體 type User struct { Id int Name string Age int } type mystrs string type Article struct { // 匿名字段 //這里的User會把我們定義的User結構體放到這里(Article) User int mystrs } func main() { s1 := Article{User{1,"22",22},2,"220"} fmt.Println(s1) } ~~~ ## 五、指針類型匿名字段 ~~~ package main import "fmt" // 結構體 type User struct { Id int Name string Age int } type mystrs string type Article struct { // 匿名字段 //這里的User會把我們定義的User結構體放到這里(Article) *User int mystrs } func main() { s1 := Article{&User{1,"22",22},2,"220"} fmt.Println(s1) } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看