The parentheses in new Foo()
specify value initialisation; this basically means that each member is zero-initialised. If instead you said new Foo
, then the members would be left uninitialised, as they are for your automatic variable.
Unfortunately, to value-initialise the automatic variable, you can't write Foo bar()
, since that declares a function. You'll need
Foo bar{}; // C++11
Foo bar = Foo(); // Historical C++