How to use structures as keys in maps

I am trying to use structure (which contains pointers ) as key in map , I want to map based on the values of structure but, I am not getting expected results.
here is sample code
https://play.golang.org/p/NGuvq40aHl8

please help me…

2 Likes

Well your ro is a pointer so it will have different adress on each iteration.

2 Likes

Is there any way to get expected result

2 Likes

Don’t use pointers https://play.golang.org/p/rj4myA57LEO

3 Likes

Thanks ,
Actually I made simple change i.e I concatenated all the values of struct fields as string and used this string as a key.I got expected results.:blush:

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.