When I write code like this:
struct foo {
operator int() const { return 1; }
};
int main() {
foo a, b;
auto tmp = (a < b);
}
it works, but while I write code like this:
struct foo {
operator string() const { return string("foo"); }
};
int main() {
foo a, b;
auto tmp = (a < b);
}
Compiler(clang++) says that error: invalid operands to binary expression ('foo' and 'foo')
I wonder why, as both string type and int type have comparison operators, but when foo has a user defined int conversion, it will implicit convert to int to compare, however when foo only has a user defined string conversion, compiler doesn't do implicit conversion though (string)a<(string)b works well.
intbeing a built in type