What is the different between anonymous field as pointer or anonymous field as usual. Consider, how I embed Foo into Bar struct.
Look at the following code snippet:
First with anonymous field as pointer
package main
import (
"fmt"
)
type Foo struct{}
func (*Foo) Run() {
fmt.Println("Hello")
}
type Bar struct {
*Foo
}
func main() {
bar := new(Bar)
bar.Run()
}
and second anonymous field as usual:
package main
import (
"fmt"
)
type Foo struct{}
func (*Foo) Run() {
fmt.Println("Hello")
}
type Bar struct {
Foo
}
func main() {
bar := new(Bar)
bar.Run()
}
What is different between them?
Update: I pick up this sample from revel webframework, how they extend a custom controller. Look at this code snippet
type App struct {
*revel.Controller
}
why do revel use pointer to embed controller struct. What is the sense of it?