I have a class with a bool
data member that is not initialized by the constructor. If I do
cout << x.myBoolDataMember;
where x
is an object of this class in which the bool
has not been initialized, I sometimes get a random number rather than 0 or 1. (I'm using gcc
.) Is this behavior compliant with the Standard
?
bool
only has two possible values,false
andtrue
. The fact thatcout << b
outputs something other than0
and1
is a consequence of the behavior not being defined, not ofb
having a "value" other thanfalse
ortrue
. – Yawl