if i do something like this...
will it allocate (is this the right term?) memory for those 960 elements? or just the ones i initialize?Code:class People
{
// all my members & such
}arrayOfPeople[960];
Printable View
if i do something like this...
will it allocate (is this the right term?) memory for those 960 elements? or just the ones i initialize?Code:class People
{
// all my members & such
}arrayOfPeople[960];
well, that code instantiates them. and if they are instantiated they are initialised/constructed.
U.
I think space for 960 instances of the class People will be assigned/allocated but I don't believe any instances of People will be initialized/constructed. If they are initialized it would be with the default constructor. Therefore, if class People contained a public data member called age, and if the default constructor assigned age a value of 0, and if each element of the array was an actual instance of class People, then you should be able to do this:
cout << arrayOfPeople[99].age;
and the value of 0 would appear on the screen. I don't have compiler to prove it, but I feel strongly that if you were to do so the compiler will indicate error on your attempt and prevent anything from appearing in the console or it will allow compilation but at runtime you will get garbage or unpredictable results appearing.
If I'm right it's sort of like building a 4 passenger car but not putting any people in it. The space is there, it's been allocated, but there is nothing in the space unless you put it there.