Perhaps this section of the spec will
help: https://golang.org/ref/spec#Method_declarations
> The type of a method is the type of a function with the receiver as first
argument
So there's only a single copy of the function code, but the argument passed
to it is copied
>From your original examp
Thank you so much.
Your explanation makes my understanding of this problem more and more clear.
However, since I have been a C programmer for a long time, I still don't
understand the implementation of the function variable in Golang very well.
I think I need to do some inspection about functi
On Wednesday, 11 August 2021 at 09:23:44 UTC+1 Brian Candler wrote:
> v := Zoo{}
> Display1(v) # v is copied
> vp := &Zoo
> Display2(vp) # vp is copied
>
>
Correction: vp := &v or vp := &Zoo{...}
> These are identical, consistent behaviours.
>
> So now onto "pointer to function". You
On Tuesday, 10 August 2021 at 22:50:00 UTC+1 lege...@gmail.com wrote:
> And I'm still a little confused here, you know when we use the struct
> method directly, it is only when the function is called that the type of
> receiver determines whether the passed struct is a pointer or a copied
> val
On Tue, 2021-08-10 at 15:54 -0700, E Z wrote:
> I quite agree with your above conclusion, and the test results also
> prove it. That seems to be the way it's designed right now, but what
> I find a little hard to understand here is why it's not designed as
> "The pointer to function assignment capt
" The pointer to function assignment captures the current receiver."
I quite agree with your above conclusion, and the test results also prove
it. That seems to be the way it's designed right now, but what I find a
little hard to understand here is why it's not designed as "The pointer to
funct
On Tue, Aug 10, 2021 at 3:50 PM E Z wrote:
> It works when I changed the code as your suggested. That's great, thanks.
>
> And I'm still a little confused here, you know when we use the struct
> method directly, it is only when the function is called that the type of
> receiver determines whether
On Tue, 2021-08-10 at 14:50 -0700, E Z wrote:
> It works when I changed the code as your suggested. That's great,
> thanks.
>
> And I'm still a little confused here, you know when we use the struct
> method directly, it is only when the function is called that the type
> of receiver determines whet
It works when I changed the code as your suggested. That's great, thanks.
And I'm still a little confused here, you know when we use the struct
method directly, it is only when the function is called that the type of
receiver determines whether the passed struct is a pointer or a copied
value.
On Tue, Aug 10, 2021 at 12:01 PM E Z wrote:
> I feel confused when I use the function pointer which point to the struct
> method. Here is the test code:
>
> /***
> package main
>
> type Zoo struct {
> Animal string
> }
>
> func (z Zoo) Display(){
> fmt.Printf("Current animal is:%s\n", z.A
I feel confused when I use the function pointer which point to the struct
method. Here is the test code:
/***
package main
type Zoo struct {
Animal string
}
func (z Zoo) Display(){
fmt.Printf("Current animal is:%s\n", z.Animal)
}
func main(){
gz := &Zoo{
Animal: "Monkey",
11 matches
Mail list logo