May 1996
Intermediate to advanced
304 pages
5h 54m
English
One of the most often heard complaints about C++ is that the compiler does things behind the programmer’s back. Conversion operators are the example most often cited. There’s a story that Jerry Schwarz, the architect of the iostream library, tells about his first attempt to support a scalar test of an iostream class object such as
if ( cin ) ...
For cin to evaluate to a true/false scalar value, Jerry first defined an operator int() conversion operator. This worked fine in well-behaved instances such as this example, but it behaved in a somewhat surprising manner under the following programmer error:
// oops: meant cout, not cin cin << intVal;
The programmer, of course, meant cout not cin. The type-safe ...
Read now
Unlock full access