Files
the-way-to-go_ZH_CN/eBook/10.3.md
2015-07-04 17:19:24 +08:00

797 B
Raw Blame History

10.3 使用自定义包中的结构体

下面的例子中main.go使用了一个结构体它来自submap? struct_pack下的包structPack。

Listing 10.5—structPack.go:

package structPack

type ExpStruct struct {
    Mi1 int
    Mf1 float32
}

Listing 10.6—main.go:

package main
import (
    "fmt"
    "./struct_pack/structPack"
)

func main() {
    struct1 := new(structPack.ExpStruct)
    struct1.Mi1 = 10
    struct1.Mf1 = 16.

    fmt.Printf("Mi1 = %d\n", struct1.Mi1)
    fmt.Printf("Mf1 = %f\n", struct1.Mf1)
}

输出:

Mi1 = 10
Mf1 = 16.000000

链接