I have a struct
and would like to implement a set
of its pointers. So I try to overload operator <
to make it happen. One limitation here is that I do not have access to write overloading code within the struct definition. How can I do it outside of the struct?
Here is what I have so far:
#include<iostream>
#include<set>
#include<vector>
using namespace std;
struct mystruct {
int label;
vector<mystruct *> neighbors;
};
bool operator < (mystruct * n1, mystruct* n2) {
return n1 -> label < n2 -> label;
};
int main() {
set<mystruct *> s;
return 0;
}
The error message is
error: overloaded 'operator<' must have at least one parameter of class or enumeration type