所以我有一個結構type Book struct { Name string Author string}這是我使用這個結構時的代碼func Add(obj string) { res, err := json.Marshal(obj) if err != nil { fmt.Println(err) } fmt.Println(string(res))}func main() { Open("./example.json") book := Book{"test", "me"} fmt.Println(reflect.TypeOf(book).String()) Add(book)}現在我想做的是在函數中傳遞該書對象或變量,Add當我嘗試這樣做時,它給了我一個錯誤。cannot use book (type Book) as type string in argument to Add那么如何解決它以及如何book在函數中將對象作為參數傳遞Add?
go - 如何將類型作為函數的參數傳遞?
慕的地6264312
2022-07-25 11:00:28