回答

收藏

golang指针的区别

技术问答 技术问答 248 人阅读 | 0 人回复 | 2023-09-12

我有两个变量golang,我不明白为什么会这样。问题:我从中得到的Models应该是struct将它用于 GORMFirst()函数。  _# o* u! M! W3 x/ U
编码:
% N1 F3 }' F- q: G
    package mainimport  "fmt")type Test struct    Test string}var Models = map[string]interface{}{    "test": newTest(),}func main()    test1 := Test{}    fmt.Println("Test 1: ")    fmt.Printf("%v",test1)    fmt.Println()    fmt.Println("Test 1 as pointer: ")    fmt.Printf("%v",&test1)    fmt.Println()    test2 := Models["test"]    fmt.Println("Test 2: ")    fmt.Printf("%v",test2)    fmt.Println()    fmt.Println("Test 2 as pointer: ")    fmt.Printf("%v",&test2)}func newTest() Test    var model Test     return model}
    ! i, b* d# L. r" h% Z/ ~% v6 |
               
( q) a/ L+ M/ `7 y1 m    解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则