Answer the question
In order to leave comments, you need to log in
How to pass a pointer to a structure to a function of another package?
Hello! Faced such a problem, it is impossible to pass a pointer to a structure to a function from another package.
Own code example:
package main
import "Project01/tools"
type TestTest struct {
Str1,Str2,Str3 string
}
func main() {
var par1 TestTest
tools.Foo(&par1)
}
package tools
import "fmt"
func Foo(par *TestTest) { // <- Тут ругается, пишет не знаю такой структуры TestTest
fmt.Println(par)
}
Answer the question
In order to leave comments, you need to log in
Your tools doesn't know anything about TestTest from main.
It makes more sense to declare it in tools. Or use interface{}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question