This has been driving me insane, and I'm not sure what's wrong:
I have a header file (KeyValueComparator.h):
Code:
#ifndef KEY_COMP
2 #define KEY_COMP
3
4 #include <string>
5 #include <iostream>
6 #include "KeyValuePair.h"
7
8 using namespace std;
9
10 class KeyValueComparator {
11 public:
12 bool operator() (const KeyValuePair a, const KeyValuePair b) const;
13 };
14
15 #endif
and a .cpp file (KeyValueComparator.cpp):
Code:
1 #include <iostream>
2 #include <string>
3 #include "KeyValueComparator.h"
4
5 using namespace std;
6
7 bool KeyValueComparator::operator() (const KeyValuePair a, const KeyValuePair b) const {
8 if(a.count==b.count) {
9 if(a.str.compare(b.str)<=0)
10 return true;
11 else {
12 return false;
13 }
14 }
15 else {
16 if(a.count>b.count) {
17 return true;
18 }
19 else {
20 return false;
21 }
22 }
23 }
and finally a running file (Main.cpp):
Code:
1 #include <algorithm>
2 #include <map>
3 #include <vector>
4 #include <iostream>
5 #include <fstream>
6 #include <string>
7 #include "KeyValuePair.h"
8 #include "KeyValueComparator.h"
9 using namespace std;
10
11 int main () {
12
13 KeyValuePair a;
14 KeyValuePair b;
15
16 KeyValueComparator cmp;
17 bool check = cmp.operator(a,b);
18 }
And I get the error:
Main.cpp: In function int main():
Main.cpp:17: error: expected type-specifier before ( token
What's going on here?