天天看點

golang快速入門-13-golang的結構體struct

與c/c++一樣

//type 關鍵字可以定義類型的别名 
type myint int

//type 關鍵字可以定義一個結構體
type Book struct 
{
    title string
    auth  string
}

// 傳值
func changeBook(book Book) 
{
    //傳遞一個book的副本
    book.auth = "666"
}

// 傳位址
func changeBook2(book *Book) 
{
    //指針傳遞
    book.auth = "777"
}           

繼續閱讀