Originally Posted by
roelof
I see that classcomp for me is teamstats.
Nope. In fact, classcomp is a primitive class (C++ classes are really structs with a different label on them). It could have been written like this:
Code:
class classcomp {
public:
bool operator() (const char& lhs, const char& rhs) const {
return lhs<rhs;
}
};
This is then used as the comparison function for the map:
Code:
map<char,int,classcomp> fourth;
This determines how the elements are sorted internally. Try this:
Code:
#include <iostream>
#include <map>
using namespace std;
class classcomp {
public:
bool operator() (const char& lhs, const char& rhs) const {
return lhs>rhs;
}
};
int main() {
map<char,int,classcomp> test;
map<char,int>::iterator it;
test['a'] = 50; // the int values are irrelevant in this program
test['b'] = 50;
test['c'] = 200;
it = test.begin();
while (it != test.end()) {
cout << it->first << endl;
it++;
}
return 0;
}
Notice I switched < to > in the compare function, so this prints out:
c
b
a
Originally Posted by
roelof
All the information I have can be found at this site en other sites.
I also very strongly recommend you get a beginner C++ book roelof. Your life will be much easier. You can probably find something used on Amazon for <$10 US.