package main
import "fmt"
//int别名
type myint int
//结构体
type Book struct {
title string
auth string
}
func change(book Book) {
//传递副本
book.title="java"
}
func changeBook(book *Book) {
//传递指针
book.title="java"
}
func main() {
var a myint = 10
fmt.Println(a)
fmt.Printf("%T\n",a)
var book1 Book
book1.auth="zhangsan"
book1.title="Golang"
fmt.Println(book1)
change(book1)
fmt.Println(book1)
//传递地址
changeBook(&book1)
fmt.Println(book1)
}
package main
import "fmt"
//类首字母大写,表示其他包能够访问
type Hero struct {
//如果类属性大写,表示属性是对外能够访问
Name string
Ad int
Level int
}
/*
func (this Hero) Show(){
fmt.Println(this.Name,this.Ad,this.Level)
}
func (this Hero) GetName() string {
return this.Name
}
func (this Hero) SetName(newName string){
this.Name=newName
}
*/
func (this *Hero) Show(){
fmt.Println(this.Name,this.Ad,this.Level)
}
func (this *Hero) GetName() string {
return this.Name
}
func (this *Hero) SetName(newName string){
this.Name=newName
}
func main() {
hero:=Hero{
Name: "zhangsan",
Ad:110,
Level:1}
hero.Show()
hero.SetName("lisi")
hero.Show()
}