Hi, can anybody tell me the difference betweeen
ClassX inst[] = { new ClassX() };
and
ClassX[] inst = null;
inst[0] = new ClassX();
What modifications should be made in the second paragraph to make it work?
Thanks.
Printable View
Hi, can anybody tell me the difference betweeen
ClassX inst[] = { new ClassX() };
and
ClassX[] inst = null;
inst[0] = new ClassX();
What modifications should be made in the second paragraph to make it work?
Thanks.
In the second example it looks like you're trying to instantiate a class into an array (not assign a class as the first element of an array). Maybe this would work:
Code:ClassX[] inst = null;
ClassX myClassX = new ClassX();
inst[0] = { myClassX };
Have you written a test program to see what the difference is?
Would save a lot of time and the answer would be correct.
The second line group creates a pointer but does NOT create an instance of an array. Ie inst[0] does not exist.
Does the first one compile?