I have a set of pointers:
set<StudentInterface*, Comparator> studentSet;
These pointers point to Student
classes which inherit from StudentInterface
and contain an int value ID
. I want to test if a certain class has a particular value for ID. My current idea for doing so is as follows:
if(studentSet.find(????->getID()) != studentSet.end()) /* do something */
Is there a way to access the data elements this way? If not, what is the shortest way (in lines of code) that I can access these elements to test them?
I don't think you can search for a particular element value of a class using find function from any STL container like vector/set/map.
You can do this in following manner :
Or if you can make a object to search, then you can do same thing as you asked in question :