I am passing a pointer to the struct to another function named someFunc()
and changing there, but it's not reflecting in caller function in this case main()
.
type Slot struct {
f1 int
f2 string
f3 []*string
}
func NewSlot(f1, f2){
return &Slot{f1: f1, f2: f2, f2: make([]*string, 0)}
}
func main() {
slots := &Slots{}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
s := scanner.Text()
sarr := strings.Split(s, " ")
fmt.Println("scanner", slots)
someFunc(slots, sarr[0], sarr[1:]...)
}
}
func someFunc(slots *Slots, cmd string, args ...string) {
slots = NewSlots(5) // return Pointer to slots with 5 and other value initialized
// But not reflecting to main() func, Why?
}