[converted top-posting to more readable form]
Wojtek is rite..
to add, you dont need to initialize the bool, even if it is defined as
static.
In general, all intrinsic data types are set to 0 when defined under global
scope or when defined static..
To be more precise, any intrinsic object that is static -- i.e.,
declared static (whether local or at file scope) or is declared in a
namespace (whether global, unnamed, or named) -- is automatically
initialized to 0, converted to the appropriate type. For user-defined
types, the default constructor will be called if it exists, and an
error will result if one does not exist but other constructors do. If
the default constructor was implicitly generated (i.e. no constructors
were defined), data members are default initialized if the object is
static. Consider:
#include <iostream>
using namespace std;
// Note: no default constructor
struct A { int i_; };
// Namespace-scoped object is default initialized
namespace { A a; }
int main()
{
// Local object is not default initialized
A b;
cout << a.i_ << ' ' << b.i_ << endl;
return 0;
}
The result of the cout demonstrates that a.i_ is initialized to 0, but
b.i_ is not (though it may happen to be 0, of course).
IME, however, it is best to make initialization explicit even in the
case of static objects since this is a rather obscure rule and
explicitness here is far from burdensome and makes the intent of the
programmer clear. Also note that the use of static to indicate "local
to this translation unit" is deprecated in C++ in favor of unnamed
namespaces.
Cheers! --M