36 lines
481 B
Go
36 lines
481 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func main() {
|
|
//创建对象实例
|
|
var T teacher = teacher{}
|
|
T.Name = "dakjda"
|
|
fmt.Println(T)
|
|
//使用指针创建对象
|
|
var t *teacher = new(teacher)
|
|
(*t).school = "没用"
|
|
(*t).age = 19
|
|
fmt.Println(t)
|
|
var s student
|
|
var p person
|
|
s = student(p)
|
|
fmt.Println(s)
|
|
}
|
|
|
|
// 定义结构体 方便内存管理
|
|
type teacher struct {
|
|
Name string
|
|
age int64
|
|
school string
|
|
}
|
|
|
|
type student struct {
|
|
age int
|
|
}
|
|
type person struct {
|
|
age int
|
|
}
|