jjzjj

newStudent

全部标签

pointers - Golang指针定义

伙计们,我有Student结构,我正在尝试将Student项目创建为*Student。我收到无效内存地址或零指针取消引用错误。varnewStudent*StudentnewStudent.Name="John"我正在这样创作。当我尝试设置任何变量时,我得到同样的错误。我做错了什么? 最佳答案 您需要为Studentstruct分配内存。例如,packagemainimport"fmt"typeStudentstruct{Namestring}funcmain(){varnewStudent*StudentnewStudent=ne

pointers - Golang指针定义

伙计们,我有Student结构,我正在尝试将Student项目创建为*Student。我收到无效内存地址或零指针取消引用错误。varnewStudent*StudentnewStudent.Name="John"我正在这样创作。当我尝试设置任何变量时,我得到同样的错误。我做错了什么? 最佳答案 您需要为Studentstruct分配内存。例如,packagemainimport"fmt"typeStudentstruct{Namestring}funcmain(){varnewStudent*StudentnewStudent=ne