I know how to embed other struct in struct within a same package, but how to embed other package's struct?
dog.go
package dog
import "fmt"
type Dog struct {
Name string
}
func (this *Dog) callMyName() {
fmt.Printf("Dog my name is %q
", this.Name)
}
main.go
package main
import "/path/to/dog"
type BDog struct {
dog.Dog
name string
}
func main() {
b := new(BDog)
b.Name = "this is a Dog name"
b.name = "this is a BDog name"
b.callMyName()
}
When I run main.go, it tell me a error:
./main.go:14: b.callMyName undefined (type *BDog has no field or method callMyName)