Chapter 45. BOOL

Difficulty: 7

Do we really need a builtin bool type? Why not just emulate it in the existing language? This Item reveals the answer.

Besides wchar_t (which was a typedef in C), bool is the only builtin type to be added to C++ since the ARM (Ellis90).

Could bool's effect have been duplicated without adding a builtin type? If yes, show an equivalent implementation. If no, show why possible implementations do not behave the same as the builtin bool.

Solution

Solution

The answer is: No, bool's effect could not have been duplicated without adding a builtin type. The bool builtin type, and the reserved keywords true and false, were added to C++ precisely ...

Get Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.