Hey guys, I have derived my class from the C++ safe bool idiom class from this page : The Safe Bool Idiom by Bjorn Karlsson
class Element : public safe_bool<>
{
public:
bool Exists() const;
// boolean_test() is a safe_bool method
bool boolean_test() const { return Exists(); };
};
When I tried to use it in the if expression like below
Element ele;
...
if(ele)
I got an error C2451: conditional expression of type 'Element' is illegal. If I try to cast it to bool like below, I got this error
Element ele;
...
if((bool)ele)
error C2440: 'type cast' : cannot convert from 'Element' to 'bool'
This is the 1st time I am using safe bool idiom, I am not sure if this is not allowed or a bug in Visual C++ 10. Any comments? Thanks in advance!