0
Map of custom class as key without < or > operator
Hi I am aware that key must be comparable for map. So, we need atleast < operator in class to have class as key of map. Refer code below and Test1 class is doing same. I was asked for other alternative and then I gave > operator. Same is there as Test2 class in code. Another approach is having < or > operator as global function rather than class members. I was asked further. Is there any other mechanism to achieve class as key for map? https://sololearn.com/compiler-playground/cIsvZgIltQE6/?ref=app
2 Réponses
+ 1
alternatively, you can use function object:
https://sololearn.com/compiler-playground/cA3H8x4Uartp/?ref=app
+ 1
Thanks MO ELomari . I got another hint also in terms of generic function to print the map.