Let's assume the following class Foo.
struct Foo
{
int i;
bool j;
};
Why do I get different results from the following lines?
int main(void)
{
//I thought the default constructor would be called
Foo foo1;
cout << foo1.i << " : " << foo1.j << endl; // " 4196352 : 0 " --> ctor not called?
//if calling the default constructor explicitly
foo1 = Foo();
cout << foo1.i << " : " << foo1.j << endl; // " 0 : 0" --> ctor called.
}
Shouldn't the default ctor be implicitly called?
According to cpp reference:
If no user-declared constructors of any kind are provided for a class type (struct, class, or union), the compiler will always declare a default constructor as an inline public member of its class.