I have a struct with the operator== overloaded.
It works fine with the first condition, but for the second condition it isn't working at all. What am i doing wrong?
Here is my code:
struct simpleLink {
int orig;
int dest;
set<int> commonKeys;
bool captured;
bool compromised;
bool operator<(const simpleLink& otherLink) const
{
if (orig == otherLink.orig) {
return dest < otherLink.dest;
}
return orig < otherLink.orig;
}
bool operator==(const simpleLink& otherLink) const
{
return ((orig == otherLink.orig) && (dest == otherLink.dest)) || ((orig == otherLink.dest) && (dest == otherLink.orig));
}
};
Main:
int main() {
set<simpleLink> test;
simpleLink secureLink;
secureLink.orig = 0;
secureLink.dest = 1;
simpleLink secureLink2;
secureLink2.orig = 1;
secureLink2.dest = 0;
test.insert(secureLink);
test.insert(secureLink2);
cout << secureLink.orig << " " << secureLink.dest << endl;
cout << secureLink2.orig << " " << secureLink2.dest << endl;
cout << "Test Size:" << test.size() << endl;
return 0;
}
Output is:
0 1
1 0
Test Size: 2
The size should be 1.
The question now is, how can i change the operator< so (0, 1) = (0, 1) and (0, 1) = (1 , 0)