//定义结构体type Dog struct { ID int Name string Age int}
//结构体测试func TestForStruct() { // var dog Dog //var声明方式 // dog.ID = 0 // dog.Name = "struct" // dog.Age = 8 //dog := Dog{ID: 1, Name: "sss", Age: 2} // := 方式
dog := new(Dog) // new方式 &{2 Tom 20} 传进去的是Dog 返回来的是指针 dog.ID = 2 dog.Name = "Tom" dog.Age = 20 fmt.Println(dog)
}