int* some = new int[5]; //
int* ssome = new int[5](); //
if written as new int () [5]
, I can understand it this way: generate space in the heap area that can hold five instances of int classes generated by a non-parameterized constructor of type int. On the other hand, `new int [5] only opens up five spaces in the heap where instances of the int class can be stored. Because the former calls the constructor and may initialize a value of 0 in the constructor, the space opened up by the former is already an array of all elements initialized to 0, while the latter has not yet been initialized.
but new int [5] ()
I can only understand that creating a compound type space on the heap using an int array of length 5 generated by a non-parameter constructor and then the no-parameter constructor of this compound type initializes all the values in the type. That seems to make sense
then I tested
int *test = new int()[5];
well, failed, compilation failed. Maybe there is no no-parameter constructor in the class int, so I am not allowed to write this, so I will create one myself, as follows:
int main(int argc, char** argv) {
class test {
public:
test() {};
~test() {};
};
// test *t = new test()[5];
test *t = new test[5](); //
}
I can"t understand why the first construction method can"t pass, but the second construction method can. I defined the class test from beginning to end, and I haven"t worked on the definition of test [] as a compound type.
and, if the constructor of the test class has and only test (int), then test * t = new test [5] ();
compilation fails, test * t = new test [5] (0);
compilation fails, test * t = new test (0) [5];
compilation fails.
then my previous understanding of new int [5] () is obviously wrong, so what is the correct understanding?
in addition, for a class that does not have a no-parameter constructor, how can I new multiple of it?