package person
type person struct {
name string
age int
}
package person
type Person struct {
name string
age int
}
package main
import "person"
func main() {
nico := person.Person{}
fmt.Println(nico) // { 0}
}
package person
import "fmt"
type Person struct {
name string
age int
}
func (p Person) SetDetails(name string, age int) {
p.name = name
p.age = age
fmt.Println("SeeDetails' nico:", p)
}
package main
import "person"
func main() {
nico := person.Person{"nico", 12}
fmt.Println("Main's 'nico'", nico)
}
func (p Person) SetDetails(name string, age int) {
p.name = name
p.age = age
fmt.Println("SeeDetails' nico:", p)
}
SeeDetails's nico: {nico 12}
Main's nico' { 0}
package person
import "fmt"
type Person struct {
name string
age int
}
func (p *Person) SetDetails(name string, age int) {
p.name = name
p.age = age
fmt.Println("SeeDetails' nico:", p)
}
SeeDetails' nico: &{nico 12}
Main's 'nico' {nico 12}
func (p Person) Name() string {
return p.name
}
강의 출처 : 노마드코더(https://nomadcoders.co)
[Nomad Coin] 비트코인 떡상을 보고 개발자가 느낀 것 (0) | 2022.07.13 |
---|---|
[Nomad Coin] Blockchain - #4.0 Introduction (0) | 2022.07.13 |
[Nomad Coin] Tour of Go - #3.6 Structs (0) | 2022.07.11 |
[Nomad Coin] Tour of Go - #3.5 Pointers (0) | 2022.07.10 |
[Nomad Coin] Tour of Go - #3.4 Slices and Arrays (0) | 2022.07.10 |
댓글 영역