Skip to content

Instantly share code, notes, and snippets.

@kitelife
Created March 9, 2014 13:06
Show Gist options
  • Select an option

  • Save kitelife/9447474 to your computer and use it in GitHub Desktop.

Select an option

Save kitelife/9447474 to your computer and use it in GitHub Desktop.
Like override
package main
import (
"fmt"
)
type User struct {
id int
name string
}
type Manager struct {
User
title string
}
func (self *User) ToString() string {
return fmt.Sprintf("User: %p, %v", self, self)
}
func (self *Manager) ToString() string {
return fmt.Sprintf("Manager: %p, %v", self, self)
}
func main() {
m := Manager{User{1, "Tom"}, "Administrator"}
fmt.Println(m.ToString())
fmt.Println(m.User.ToString())
}
@kitelife

kitelife commented Mar 9, 2014

Copy link
Copy Markdown
Author

Manager: 0xc080043de0, &{{1 Tom} Administrator}
User: 0xc080043de0, &{1 Tom}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment