package main
import "fmt"
import "reflect"
type Age int
func (age Age) CanDrink() bool {
age++
return age >= 18
}
func main() {
var age Age = 11
Age.CanDrink(age)
// (*Age).CanDrink(age) // cannot use age (type Age) as type *Age in
argument to (*Age).CanDrink
(*Age).CanDrink(&age)
fmt.Println(age) // 11
fmt.Println(reflect.TypeOf(Age.CanDrink)) // func(main.Age) bool
fmt.Println(reflect.TypeOf((*Age).CanDrink)) // func(*main.Age) bool
}
Why is the parameter of (*Age).CanDrink is a pointer? It is not reasonable.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.