配置文件等

This commit is contained in:
2022-03-01 13:37:57 +08:00
parent 4b37574544
commit 44a0c2a7a1
13 changed files with 709 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
```go
type Car struct {
color string
size string
}
```
方式一:使用T{…}方式,结果为值类型
```go
c := Car{}
```
方式二:使用new的方式,结果为指针类型
```go
c1 := new(Car)
```
方式三:使用&方式,结果为指针类型
```go
c2 := &Car{}
```
以下为创建并初始化
```go
c3 := &Car{"红色", "1.2L"}
c4 := &Car{color: "红色"}
c5 := Car{color: "红色"}
```
构造函数:
在Go语言中没有构造函数的概念,对象的创建通常交由一个全局的创建函数来完成,以
NewXXX 来命名,表示“构造函数”
```go
func NewCar(color,size string) *Car {
return &Car{color,size}
}
```