Creating object with new always implicitly calls constructor, it's a part of the standard and this approach is quite handy. So writing neirons[i] = new Neiron[this->eachLayerCount[i]]; means "create array with N objects of Neiron class and store pointer to that array into neirons[i]". As a result, dynamic buffer is allocated, N objects are created in it(constructor is called).
Current case doesn't differ much from creating a single object neirons[i] = new Neiron;, where you might get used to implicit constructor calling.
Related part of C++ standard:
Default constructors ... are called to create class objects of dynamic
storage duration (3.7.4) created by a new-expression in which the new-initializer is omitted (5.3.4) ...
EDIT
I might have misinterpreted the question. It looks like you are wondering on some fields being initialized by the time when only default constructor is called, which doesn't do anything on them. There should be no magic, not initialized variable gets its value from the garbage left on dynamic memory. If you see some meaningful values instead of random stuff or zeroes, you might have put your new object into the memory, which has just been freed from being used for the same purpose. If you aren't convinced with this explanation, please create MCVE, so we can reproduce and explain scenario step by step.
EDIT 2
Thanks to clarifications, I see the concern now. Here is what is going within the MCVE:
test[i] = new Test[layers[i]];
Dynamic buffer is allocated and filled with layers[i] objects. Objects are created with default constructor, so their fields aren't initialized, but contain garbage left on the heap (e.g. fieldA of these objects is set to -842150451 or any other meaningless value).
for (int j = 0;j < layers[i];++j)
{
test[i][j] = Test(counter);
counter++;
}
This sample uses anonymous object in the right side, so it is actually an equivalent of this one:
for (int j = 0;j < layers[i];++j)
{
Test temporaryObject(counter);
test[i][j] = temporaryObject;
counter++;
}
Program creates temporary object on stack using parametrized constructor, then initializes test[i][j] with it, destroys temporary object and repeats it for next i/j.
First iteration (i=0, j=0) allocates uninitialized buffer in stack to store temporary object and calls parametrized constructor for it, so you can see fieldA modified in constructor from garbage to zero. Then temporary object is used to init test[i][j] and is destroyed, freeing memory.
Second iteration (i=0, j=1) allocates exactly the same area of memory to store temporary object (you can verify it by inspecting &temporaryObject or checking this in parametrized constructor). Since this memory contains leftovers from previous usage as temporary object, you see constructor changing fieldA from 0 (left from previous iteration) to 1. And so on.
I want to stress, that process above is related to temporary object only. test[i][j] are initialized twice only:
- with random garbage during creation with
test[i] = new Test[layers[i]];
- with actual value from temporary object with
test[i][j] = Test(counter);
std::vector?forloop? if not, then it's possible that you're accessing unallocated memory which triggers undefined behaviour. You cannot assign toneirons[i]beforeneironsis created.