“convertible to bool” simply means anything which can meaningfully be used in a boolean context (e.g. in an if
condition). This makes sense in implicit conversions. Imagine an object which you want to use in a boolean context, e.g. std::fstream
:
ifstream ifs("filename");
while (ifs >> token)
cout "token " << token << " read." << endl;
Here, ifs
is convertible to boolean. Well, actually, it isn't. Rather, it is convertible to something that, in turn, is convertible to bool
. This is to prevent such statements:
int b = ifs;
The reasoning is that such a statement is most probably not intended and the compiler should therefore prevent it. By returning a “convertible to bool” rather than a bool
, this is achieved because two user-defined implicit conversions can't be chained in one expression.
In this context, you might want to look up the safe bool idiom. Chris has already alluded to one possible implementation, using void*
as a return type. Usually, the this
pointer is then used to represent true
. This is what gets used by the STL. However, this is unfortunately still flawed. Several alternatives have been proposed (neatly wrapped up in the article I've linked above) and as far as I know, have also been included into C++0x for consideration. I'm not aware of the current status of these proposals, though.