I have two structs abc2
and abc
struct abc2 {
const int& data;
abc2(const int& cdata) : data(cdata) {}
};
struct abc {
const int &data;
abc(const int& cdata) : data(cdata) {}
bool operator <(const abc2& rhs) const {
return data < rhs.data;
}
};
And I have a map of abc
and int
std::map<abc, int> test;
test[abc(1)] = 2;
test[abc(2)] = 3;
And I want to search test
with struct abc2
. I assumed it would work because I have overloaded the < operator in abc
to accept abc2
auto foo = test.find(abc2(1));
However this does not work, and I get a compile time error saying cannot convert argument 1 from 'abc2' to 'const abc &'
Is there a workaround for achieving this? It is essential that I achieve the lookup using abc2
.