Why can't I call a pointer method on a temporary object?

109 Views Asked by At
type A struct{}    
func (*A) F() {}

func main() {    
    a := A{}

    a.F()      // OK
    (&a).F()   // OK

    (&A{}).F() // OK    
    A{}.F()    // Error: cannot call pointer method F on A
    (A{}).F()  // Error: cannot call pointer method F on A
}

Why can't I call a pointer method on a temporary object in golang?

0

There are 0 best solutions below