fork download
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6.  
  7. type Human struct {
  8. name string
  9. job Job
  10. }
  11.  
  12. type Job struct {
  13. name string
  14. position string
  15. }
  16.  
  17. func NewHuman(name string, jobname string, position string) *Human {
  18. return *Human{
  19. name: name,
  20. job: Job{
  21. name: jobname,
  22. position: position,
  23. },
  24. }
  25. }
  26.  
  27. func (h Human) JobPosition() string {
  28. return h.job.position
  29. }
  30.  
  31. func (h *Human) SetJobPosition(position string) {
  32. h.job.position = position
  33. }
  34.  
  35. func main() {
  36. fmt.Println("Hello World!")
  37. h1 := NewHuman("Shinzou Abe", "politician", "prime minister")
  38. fmt.Println(h1.JobPosition())
  39. h2 := NewHuman("Yukio Hatoyama", "jobless", "master of baka")
  40. fmt.Println(h2.JobPosition())
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
# _/home/7M01ac
./prog.go:24: invalid indirect of Human literal (type Human)
stdout
Standard output is empty