|
-
December 14th, 2010, 04:55 AM
#1
Safe Boolean Idiom cannot compile with Visual C++ 10(2010)
Hey guys, I have derived my class from the C++ safe bool idiom class from this page : The Safe Bool Idiom by Bjorn Karlsson
Code:
class Element : public safe_bool<>
{
public:
bool Exists() const;
bool boolean_test() const { return Exists(); }; // boolean_test() is a safe_bool method
}
When I tried to use it in the if expression like below
Code:
Element ele;
...
if(ele)
I got an error like error C2451: conditional expression of type 'Element' is illegal. If I try to cast it to bool, I got this error,
Code:
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?
Last edited by CBasicNet; December 14th, 2010 at 07:55 AM.
Reason: Added missing semicolon to Element ele
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|