#include <iostream>
using namespace std;
struct A
{
explicit operator bool() const
{
return true;
}
operator int()
{
return 0;
}
};
int main()
{
if (A())
{
cout << "true" << endl;
}
else
{
cout << "false" << endl;
}
}
My expectation was that A()
would be contextually converted to bool
using my operator bool()
, and therefore print true
.
However, the output is false
, showing that operator int()
was invoked instead.
Why is my explicit operator bool
not called as expected?