当前位置:网站首页>Go language self-study series | golang nested structure
Go language self-study series | golang nested structure
2022-04-23 08:50:00 【COCOgsta】
Video source :B standing 《golang Introduction to project practice [2021 newest Go Language course , There is no nonsense , Dry only ! Ongoing update ...]》
Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !
Attach summary sticker :Go Language self-study series | Summary _COCOgsta The blog of -CSDN Blog
go Language has no idea of object-oriented programming , There is no inheritance , However, this effect can be achieved through structure nesting .
The following is an example to demonstrate how to realize structure nesting , If there is a person Person Structure , This man also has a pet Dog Structure
So let's see :
Dog Structure
type Dog struct {
name string
color string
age int
}
Person Structure
type person struct {
dog Dog
name string
age int
}
Visit them
package main
import "fmt"
type Dog struct {
name string
color string
age int
}
type person struct {
dog Dog
name string
age int
}
func main() {
var tom person
tom.dog.name = " tearful "
tom.dog.color = " Black and white flower "
tom.dog.age = 2
tom.name = "tom"
tom.age = 20
fmt.Printf("tom: %v\n", tom)
}
Running results
[Running] go run "d:\SynologyDrive\ software development \go\golang Introduction to project practice \goproject\360duote.com\pro01\test.go"
tom: {
{ tearful Black and white flower 2} tom 20}
版权声明
本文为[COCOgsta]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230822135725.html
边栏推荐
- Judgment on heap (25 points) two insertion methods
- MATLAB入门资料
- 使用flask和h5搭建网站/应用的简要步骤
- LINQ Learning Series ----- 1.4 anonymous objects
- K210 learning notes (II) serial communication between k210 and stm32
- LaTeX数学公式
- L2-023 图着色问题 (25 分)(图的遍历)
- MySQL查询两张表属性值非重复的数据
- 共享办公室,提升入驻体验
- Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard
猜你喜欢
随机推荐
政务中台研究目的建设目标,建设意义,技术创新点,技术效果
Solidity 问题汇总
Restore binary tree (25 points)
LLVM之父Chris Lattner:编译器的黄金时代
单片机数码管秒表
swagger文档导出自定义v2/api-docs拦截
Download and install bashdb
tsdf +mvs
正点原子携手OneOS直播 OneOS系统教程全面上线
洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別
2021 Li Hongyi's adaptive learning rate of machine learning
1099 establish binary search tree (30 points)
Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
Concave hull acquisition method based on convex hull of point cloud
Introduction to GUI programming swing
Learn SQL injection in sqli liabs (Level 11 ~ level 20)
搜索树判断 (25 分)
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
JVM工具之Arthas使用
【原创】使用System.Text.Json对Json字符串进行格式化









