'init'
This commit is contained in:
35
main/pt.go
Normal file
35
main/pt.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user