Doubt help required

package main

import (
“fmt”
)

func main() {
fmt.Println(“Hello, playground”)
var data A
data.B.Value1 = “abc”
fmt.Println(data.B.Value1)

}

type A struct {
Hello string
B *struct {
Value1 string
Value2 string
}
}

throwing invalid pointer how can I overcome. B struct will be in A cant write outside A

You could make B not be a pointer: https://play.golang.org/p/RdiU0jG4AoY

You could also create a MakeA function: https://play.golang.org/p/A-H3ra5pVov

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.