Can any one help me why is the below code giving undefined:register error
I am trying to understand the call by reference and call by value.
package main
import (
"fmt"
)
type MyStruct struct {
name string
id int64
}
var (
s MyStruct
u int
)
func (u MyStruct) register() {
fmt.Println(u.name, u.id)
fmt.Println(u.name, u.id)
fmt.Println(u)
s.name = "vij"
fmt.Println(u)
}
func main() {
s := MyStruct{"deb", 11273090}
r := register()
fmt.Print("Inside Main****")
fmt.Print(s)
}
./prog.go:29:7: undefined: register
Top comments (9)
You can use markdown syntax to present the code better
Example
Hi Santhosh, thanks for the suggestion. The thing is that when i format the code written in [I'm an inline link]play.golang.org/ it automatically indents the body.
Register is a method.
You need to call it by s.register()
And register doesn’t return anything.
Many many thanks Emanuele it helped...Sorry guys for a simple question.. please bear with me am a Novice..:(
Can you improve the title of your question please. If not done in 24 hours, the help tag will be removed.
Sorry if that was harsh ...Is this better Si
Thanks for revising it, but not much better I'm afraid. The title should be a summary of the issue, for example, for this question, it could be "function undefined in Go".
It just gives people more context into the issue without having to click on the question 😊
Edit: also no need to apologise, phrasing questions is hard. It's something you'll learn with experience.
Thank you for your suggestions Si.
Sure :) keep coming back if you need help.
I've been working with Go for a few years, so ping me if you need to.