Thank you very much Ian! I am using a pointer to the map because i want to pass the map by reference, not by value. Those maps can become pretty large and are being handed down through a couple of function calls and i don't want them to be copied over and over again.
I read the document you referenced, but am not able to understand… So i can use interface{} or any just to generalize simple types? Why is the compiler accepting then a p_Values map[string]interface{} as a parameter of a function? - What would be a compatible data-type to pass as this parameter? Thank you very much in advance for your help. Best regards from Charleston (WV), Frank/2 Ian Lance Taylor schrieb am Dienstag, 14. März 2023 um 21:40:27 UTC-4: > On Tue, Mar 14, 2023 at 6:27 PM Frank Jüdes <jue...@gmail.com> wrote: > > > > i still somewhat new with Go and need a little tutoring: I have to > create Excel files, using the excelize package and wrote a little function > to store data from a map[string]int64 into a column within the worksheet: > > > > // > ------------------------------------------------------------------------------------------------- > > // Store a slice of int64 data items into the cells of a column > > // > ------------------------------------------------------------------------------------------------- > > func SetColumnValuesInt64(xf *excelize.File, > > p_SheetName string, > > p_StartRow int, > > p_Column rune, > > p_CellStyle *excelize.Style, > > p_Keys *UTL_StringSlice.T_StringSlice, > > p_Values *map[string]int64) { > > Row := p_StartRow > > StyleID,_ := xf.NewStyle(p_CellStyle) > > for _,Key := range(*p_Keys) { > > CellAddress := fmt.Sprintf("%c%d",p_Column,Row) > > xf.SetCellValue(p_SheetName,CellAddress,(*p_Values)[Key]) > > xf.SetCellStyle(p_SheetName,CellAddress,CellAddress,StyleID) > > Row++ > > } // END for > > } // END SetColumnValuesInt64 > > > > Basically the function iterates through a slice of strings, containing > the key-values for the data-map and then calls the SetCellValue function > from the excelize package to store the number into the cell. > > Now i have another set of data, stored into a map[string]float64 … > > So i duplicated the above function, just replacing the red line with > > p_Values *map[string]float64) { > > > > Basically it is the same code, just the parameter-type is different. I > looked into the definition of the function SetCellValue and saw that it is > using the empty interface as parameter for the value, so i tried to define > my function with > > p_Values *map[string]interface{}) { > > > > The function compiles fine, but if i try to use it with a > *map[string]int64 as a parameter, the compiler objectst with the message > »cannot use Amounts (variable of type *map[string]int64) as type > *map[string]interface{} in argument to ExcelFormats.SetColumnValues« > > > > Can somebody please give me hint what i am doing wrong? > > First I'll note that it's quite unusual to use a pointer to a map. > Maps are reference types. If you pass a map to a function, and that > function adds values to the map, the caller will also see the new map > entries. > > That said, the error message seems clear enough: a function that > expects a pointer to map[string]any can't take an argument that is a > pointer to map[string]int64. The types any and int64 are different > types. You can't interchange them. See > https://go.dev/doc/faq#covariant_types for a related issue. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/48a30be4-9229-4c6c-9503-12cbaa90c35an%40googlegroups.com.