I have read the safe bool idiom, and the author
give four defect implements. But I can't find any
difference between the void* and nested_class*
solution.
// operator void* version
class Testable {
bool ok_;
public:
explicit Testable(bool b=true):ok_(b) {}
operator void*() const {
return ok_==true ? this : 0;
}
};
// nested class version
class Testable {
bool ok_;
public:
explicit Testable(bool b=true):ok_(b) {}
class nested_class {};
operator const nested_class*() const {
return ok_ ? reinterpret_cast<const nested_class*>(this) : 0;
}
};
Cound anybody here tell me what is the differences between
the operator void* version and nested class version?
Thanks in advance!