Advertisement
Guest User

Untitled

a guest
Oct 24th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. // ptr.go.
  2.  
  3. package main
  4.  
  5. import "fmt"
  6.  
  7. type ClassX struct {
  8. Name string
  9. Age int
  10. }
  11.  
  12. func main() {
  13. var obj *ClassX
  14. initApp(obj)
  15. fmt.Println(obj)
  16. return
  17. }
  18.  
  19. func initApp(x *ClassX) {
  20. tmp := NewClassXObject()
  21. x = tmp
  22. fmt.Println("tmp:", tmp)
  23. fmt.Println("x:", x)
  24. }
  25.  
  26. func NewClassXObject() *ClassX {
  27. x := new(ClassX)
  28. x.init()
  29. return x
  30. }
  31.  
  32. func (o *ClassX) init() {
  33. o.Age = 123
  34. o.Name = "John"
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement