I am curious if this type of declaration for structs
t := Person{"girlie", 12}
only works if its type is declared in the same file.
Below are my files.
file st.go, type def structure inside to be used in main func
package structs
type person struct {
age int
name int
}
file practice.go, main function:
package main
import(
"fmt"
"structs/dir"
)
func main() {
var s dir.Person
s.Name = "She"
s.Age = 12
>> t := Person{"girlie", 12}
fmt.Println(s.Name)
fmt.Println(t.Name)
}
As you can see an error occurs where instance t is declared.