Regarding overloading ()

In the video we have overloaded the () operator. I don’t really understand why we have done that. Please explain

hi @abhi_11,
here we are defining our own class(Student) but using the default map, so we need to tell the hash map how to make the hashing of the data we are providing as its not known to the compiler beforehand.
So this is done by passing the HashFn here which overloaded () operator. So whenever the map will insert anything it will use that hashing function

hope this clears the doubt :slight_smile:

hi, I know that we have defined our custom student class and using STL’s map but why we have to overload the () operator. Why can’t we just pass the HashFn as we usually do. For example in sort() and priority queue STL, we just provide comparator function.

@abhi_11, have you done it using custom class in priority queue its done same way
read here : https://www.geeksforgeeks.org/stl-priority-queue-for-structure-or-class/

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.