当前位置:网站首页>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
边栏推荐
- 洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
- 是否同一棵二叉搜索树 (25 分)
- Enterprise wechat application authorization / silent login
- xctf刷题小记
- ONEFLOW learning notes: from functor to opexprinter
- L2-3 浪漫侧影 (25 分)
- 1099 establish binary search tree (30 points)
- STM32F103ZET6【标准库函数开发】----库函数介绍
- 洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置
- 经典题目刷一刷
猜你喜欢

Chris LATTNER, father of llvm: the golden age of compilers

2022-04-22 OpenEBS云原生存储

idea底栏打开services

DJ音乐管理软件Pioneer DJ rekordbox

洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置

L2-3 romantic silhouette (25 points)

2021李宏毅机器学习之Adaptive Learning Rate

JVM工具之Arthas使用

The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution

Automatic differentiation and higher order derivative in deep learning framework
随机推荐
Idea import commons-logging-1.2 Jar package
Basic usage of synchronized locks
valgrind和kcachegrind使用運行分析
调包求得每个样本的k个邻居
Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard
Technological innovation in government affairs in the construction of Digital Government
After a circle, I sorted out this set of interview questions..
LaTeX论文排版操作
Share the office and improve the settled experience
2021李宏毅机器学习之Adaptive Learning Rate
Solidity 问题汇总
洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
四张图弄懂matplotlib的一些基本用法
扣缴义务人
Anonymous type (c Guide Basics)
Restore binary tree (25 points)
Yangtao electronic STM32 Internet of things introduction 30 steps notes 1. The difference between Hal library and standard library
怎样读取Excel表格到数据库
ESP32程序下载失败,提示超时