diff --git a/struct/pointer.go b/struct/pointer.go new file mode 100644 index 0000000..2997bf0 --- /dev/null +++ b/struct/pointer.go @@ -0,0 +1,22 @@ +package main + +import "fmt" + +type Hoge struct { + Name string +} + +func (h Hoge) foo() { + fmt.Println(h.Name) +} + +func (p *Hoge) bar() { + fmt.Println(p.Name) +} + +func main() { + v := Hoge{"hoge"} + v.foo() + v.bar() +} + diff --git a/struct/struct3.go b/struct/struct3.go index f19478c..cb08d18 100644 --- a/struct/struct3.go +++ b/struct/struct3.go @@ -14,6 +14,6 @@ func main() { - v1 := SampleStruct{1, "taro"} - v1.hoge() + v := SampleStruct{1, "taro"} + v.hoge() }