I am working trough a course "Mastering Go Programming" by "Mina Andrawos". The following adapted code does not execute as expected:
a) main.go - package main
import (
"fmt"
"interfaces/linklist"
)
func main() {
node := linklist.NewNode()
node.SetValue(1)
fmt.Println("Get Value: ", node.GetValue())
}
b) linklist.go - package linklist
// Node struct
type Node struct {
next *Node
value int
}
// SetValue function
func (sNode Node) SetValue(v int) {
sNode.value = v
}
// GetValue function
func (sNode Node) GetValue() int {
return sNode.value
}
// NewNode constructor
func NewNode() Node {
return Node{}
}
Problem: The code "sNode.value = v" in "linklist.go" is never executed. The program outputs "0" instead of "1". In debug mode the "sNode.value = v" code is skipped when "node.SetValue(1)" is executed in the main function.
What must be done so that the program prints "Get Value: 1"?
Environment: