I don't understand the following function definition. what's the meaning of u *Unit in this function definition? I don't think it is returned value, cannot find the answer in Go tutorial.
func (u *Unit) processImage(){
....
}
I don't understand the following function definition. what's the meaning of u *Unit in this function definition? I don't think it is returned value, cannot find the answer in Go tutorial.
func (u *Unit) processImage(){
....
}
In "func (u *Unit) processImage()" function, "u *Unit" is parameter/input and also receiver, it's depend what contains in processImage(). For example:
func (u *Unit) processImage() {
u.sum = u.x + u.y
}
In this case processImage() used values of x and y fields of struct "Unit" as parameters/input to update value of "sum" and then return u (with new value of sum). A method with (u *Unit) was called Pointer receivers.
A method like below with (u Unit) was called value receivers:
func (u Unit) processImage() int {
return u.x + u.y
}
In value receivers, u contains parameter/input values, it's not a receiver.