go 下面定义嵌套结构

package main

import (
"fmt"
) const (
URL = "http://www.163.com"
UID = "admin"
TOKEN = ""
) type Ren struct {
Phone string
} type Student struct {
Ren
Name string
Age int
}
type Teacher struct {
Ren
Name string
Age int
} func main() {
a := Student{
Ren: Ren{Phone: ""},
Name: "test1",
Age: ,
}
b := Student{
Ren: Ren{Phone: ""},
Name: "kkk2",
Age: ,
} fmt.Println(a, b)
}

结构定义方法

type Teacher struct {
Name string
Age int
} func main() {
c := Teacher{}
c.Say()
} func (t Teacher) Say() {
fmt.Println("say test test!")
}
上一篇:js轮播(qq幻灯片效果)


下一篇:递归遍历嵌套结构(多层List)中的元素 ------Python