Bool types are smaller than Int types, thus use less room in memory. Depending on the system you're compiling on/for, an Int can be 4 - 8 bytes, whereas a Bool is 1 byte (as can be seen in this MSDN article)
Couple this with some of the aspects of KISS and good program design, and it becomes obvious why it's better to use a bool to store a variable that will only ever have 2 values.
Why over complicate things with an object that can store a wide range of values, when you are sure that you only ever need to store 1 of 2 different values?
What happens in the system that uses an int, if you store 75 in there? If you've added extra conditionals
if (value >= 0 )
return true; //value is greater than 0, thus is true
else
return false; //value is 0 or smaller than 0, thus is false
or
if (value == 0)
return false; //value is greater than 0, thus is true
else if (value == 1)
return true; //value is 0 or smaller than 0, thus is false
then you're covered for this situation. But if you haven't, then you're not.
You could also have a case (depending on how you're changing the value of the int) where you have a buffer overrun, and the value "resets" back to 0 or the lower bound of your int (which could be somewhere in the region of -127 to −9,223,372,036,854,775,808, depending on your target architecture) what happens in your code then?
However, if you used a bool you could use something like this:
if(continueBool == true)
return true;
else
return false;
Or even:
return (continueBool== true) ? true : false;
or even:
return continueBool;
Depending on your compiler, there might be optimizations that it can perform on code that uses Bools to store mapped true/false values. Whereas, there might not be optimizations it can perform for Ints used to store mapped true/false values.
We've also got to remember that C++ (along with C, Assembly and FORTRAN) is used to write highly efficient, small and fast code. So, it would be better to use a Bool in this instance - especially if you are being marked on your use of variables, memory, cache or processor time.
A similar question would be: why would I store an integer (value) in a float?
Answer: You shouldn't, because there's no point.
Long story short: As your teacher/tutor/lecturer/professor to go over the sizes of different value types with you (in case you missed it), and why they're important in Software Development.
I hope that helps as a starting point (I also hope that it doesn't come across as pedantic)
int
is to store an integer and the purpose of abool
is to store a boolean value (true
orfalse
). Using abool
IMO reflects its use much better than using anint
.typedef int Bool
in order to make it clear that they were using a boolean. C++ integrated support forbool
into the language, as did C99 with the (rather ugly)_Bool
keyword.bool
", it's about why do we have different names for similar types (likelength_t
) and why it's important that compiler checks types.