HI All,
This doubt could be simple but i can't figure out myself.
Basically my task is to go through a list of names (with associated int values), check if it already exists in a std::set , if not add it.
So std::set<myclass> goes like this...
my main class would goCode:cmyclass{ cmyclass(CString str, int int1, int int2){ m_str = str; m_int1 = int1; m_int2 = int2; } cmyclass operator<(const cmyclass &right) const; Cstring m_str; int m_int1; int m_int2; }
I can understand what i am doing in the main program...but not sure why i need to override operator< here and what goes in there? Can someone help me here?Code:std::set<cmyclass> m_myclass; cmyclass myclass(str1, int1, int1); std::set<myclass>::iterator Iter1 = m_myclass.find(myclass); if(Iter1 == m_myclass.end()){ //if doesn't exist in the set add it. std::pair<std::set<cmyclass>::iterator, bool> IterAdd = m_myclass.insert(myclass); }
thanks




Reply With Quote