When I use new[] to create an array of my classes:
int count = 10;
A *arr = new A[count];
I see that it calls a default constructor of
int
is not a class, it's a built in data type, therefore no constructor is called for it.
Built-in types don't have a default constructor even though they can in some cases receive a default value.
But in your case, new
just allocates enough space in memory to store count
int
objects, ie. it allocates sizeof<int>*count
.
See the accepted answer to a very similar question. When you use new[]
each element is initialized by the default constructor except when the type is a built-in type. Built-in types are left unitialized by default.
To have built-in type array default-initialized use
new int[size]();