http://objectscape.blogspot.de/2013/09/inner-pattern-to-mimic-method.html
Am Dienstag, 23. Juni 2015 07:57:38 UTC+2 schrieb prajakta....@gmail.com:
I am trying to pass the parent struct type to a method
package main
import "fmt"
type Child struct {
Parent //embed
Attr string
}
type Parent struct {
Attr1 string
}
func setf(p Parent) {
fmt.Println(p)
}
func main() {
var ch Child
ch.Attr = "1"
ch.Attr1 = "2"
setf(ch) // This does not work - cannot use ch (type Child) as type
Parent in argument to setf
}
How do I resolve this problem?
--package main
import "fmt"
type Child struct {
Parent //embed
Attr string
}
type Parent struct {
Attr1 string
}
func setf(p Parent) {
fmt.Println(p)
}
func main() {
var ch Child
ch.Attr = "1"
ch.Attr1 = "2"
setf(ch) // This does not work - cannot use ch (type Child) as type
Parent in argument to setf
}
How do I resolve this problem?
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.