Instead of defining your own class for the key and defining your own comparison operators, since you care about the roll number and semester, I would use std :: pair.
#include <utility> #include <map> // This maps an std::pair of (roll number, semester) to a StudentRecord. std::map<std::pair<int, int>, StudentRecord> studentMap; studentMap.insert(std::pair<std::pair<int, int>, StudentRecord>(std::make_pair(100, 100), StudentRecord());
If you use something other than int for the number and semester, you can easily use the ones that are paired. Just keep in mind that if you use custom structures for these objects, they will need to implement equality and comparison operators, in which case you will lose the advantage of using a pair, instead of directly using any other structure.
Mitch lindgren
source share