Quote:
Originally posted by Musaran
Except if you have overloaded "bool" cast.
You could have a numerical class considered "true", even though it's arithmetic value would be 0 (not to be recommended).
Classes such as "cin" have no arithmetic value, but have a boolean one.
In which case, it's not an implied cast anymore, is it?
Quote:
What to use as a null-pointer/value is a very difficult problem, and C++ solved it by making 0 a magical number that can safely and automatically be turned into any of the fundamental types, including pointers, where it means appropriate null-pointer.
Do you remember something along the lines of "magical numbers are bad" ?
Not in this instance. The proscription against "magic numbers" is quite different.
Quote:
What are the various meanings of "0" here ?When I must specify null-pointer, I feel NULL is much more appropriate and explicit than 0.
When I must specify null-char , I feel '\0' is much more appropriate and explicit than 0.
When I must specify error return, I feel enum is much more appropriate and explicit than 0 (or else).
I use 0 only as number zero, in computations and/or indices.
Fair enough. I'm not trying to bully you into never using NULL. I happen to think that 0 is perfectly legible in all cases. Context is all. In English, there are over a dozen meanings for the sound "so" (or "sew"). You can generally figure out which one a person means from context. For the same reason, I see no problem with zero having slightly different meanings in different places.
One thing, though. If you happen to compile your C++ program in an environment where NULL is defined as ((void*)0) [or something similar], be prepared to be overwhelmed with error messages.