calvincani
(Calvin Cani)
November 5, 2018, 10:05am
1
I created a struct in another package in another directory. The struct name is Person. Now I want to create an instance of a person in main package and use that person like so:
func main() {
p := Person {
"Joe",
"Doe",
time.Date(1971, time.September, 1, 0, 0, 0, 0, time.UTC),
"xxx@xxxx.com,
"Helena",
}
}
but it does not want to work and I cannot import the package because it just gets removed on save
std282
(Alexander)
November 5, 2018, 10:59am
2
To use a type from another package, you need to prepend type with package name like this:
package main
import "yourpkg"
func main() {
p := yourpkg.Person {
"Joe",
"Doe",
time.Date(1971, time.September, 1, 0, 0, 0, 0, time.UTC),
"xxx@xxxx.com",
"Helena",
}
}
1 Like
calvincani
(Calvin Cani)
November 5, 2018, 11:10am
3
Iām learning thank you very much
system
(system)
Closed
February 3, 2019, 11:10am
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.