The difference is when you use objects that are "Trivially Constructible", which means types that don't really have a constructor and neither do its members/base classes (including built-in types like int
, double
). Let's have a look at an example:
struct Foo
{
int val1;
int val2;
};
Here Foo
does not have a constructor. When we create an object of type Foo
, we can leave its members initialized with indeterminate values. Here's how we do it:
Foo* pf = new Foo;
Here pf->val1
and pf->val2
essentially have some garbage values.
We can also zero-initialize
that object like so:
Foo* pf = new Foo();
Here pf->val1
and pf->val2
are initialized with zero. If they had a different type, like a pointer, they would have a different value, like null-pointer.
If the object does have a default constructor, the two examples do exactly the same thing.