Explanation of working of overloaded == operator in case of collisions

Whats the difference between the working of this HashFn class and the bool operator == overloading or how are they both used in hashing in this case?

bool operator == (const Student &s){

return rollno==s.rollno;

}

here how is “rollno” used? Because s.rollno is passed by reference throught the function but “rollno” points to what?

class HashFn{

public:

size_t operator()(const Student &s) const{
    return s.firstname.length()+s.lastname.length();    
}

};

I would be really grateful for an elaborate explanation on this…

hello @bishal_c

compiler dont know how to compare two student objects, so its user responsibiltiy to define explicitly how to compare them , that is why we are overloading == operator .

at the time of searching, comaprision between two students will be required so there == (overloaded function) will be used.

roll no is roll no of object which we are trying to search in table. whereas s.rollno is roll no of object where we are present during search .

here we are writing definition of hash function, i,e on what criteria we should hash the student object.
in this case we are taking legnth of name as hasing criteria

I didn’t get the part which you rereferred as searching…how does that take place ?

when we need to check whether particular student presernt or not in the map then at that time, comaprision is required between student object we are looking and available student object present in map.

thank you for making it clear :slight_smile: