Does Go support anonymous methods for structures and if they do how do you create and call them?
This is the code I've been trying to get work but I'm unsure if Go(go version go1.1.2 linux/amd64) supports anonymous methods to structures.
package main
import (
"fmt"
)
type Person struct{
name string
age int
}
func (p Person) get_details() string {
return fmt.Sprintf("Name->%s, Age->%d", p.name, p.age)
}
func main() {
p := Person{name:"G4143", age:5}
//simple anonymous function which works
fmt.Println(func(i int)int{return i * i}(34))
str := p.get_details()
fmt.Println(str)
//anonymous method which won't compile
str = p.func(p Person)()string{return fmt.Sprintf("Name->%s, Age->%d", p.name, p.age) }()
fmt.Println(str)
}
I thank-you for any guidance..