bool “bar” is by default true, but it should be false, it can not be initiliazied in the constructor. is there a way to init it as false without making it static?
Simplified version of the code:
foo.h
class Foo{
public:
void Foo();
private:
bool bar;
}
foo.c
Foo::Foo()
{
if(bar)
{
doSomethink();
}
}
In fact, by default it’s not initialized at all. The value you see is simply some trash values in the memory that have been used for allocation.
If you want to set a default value, you’ll have to ask for it in the constructor :
UPDATE C++11:
If you can use a C++11 compiler, you can now default construct instead (most of the time):