Thank you very much for taking the time to reply :)
I changed delete[] pupil; to
1 2 3 4
|
for(std::size_t i = 0; i < (sizeof(pupil)/sizeof(pupil[0])); i++)
{
delete pupil[i];
}
|
Is this the correct way to delete the objects? What if I declare the pupil array as
Student *pupil = new Students[4];
, will delete[] pupil; delete the objects stored in the array?
When I used pupil[0] instead of &pupil[i], I got the following output:
Address for 1 0x28fe4c
Address for 1 0x692870
Address for 2 0x28fe4c
Address for 2 0x692880
Address for 3 0x28fe4c
Address for 3 0x692890
Address for 4 0x28fe4c
Address for 4 0x6928a0
Sudent ID: 1 has score of: 70
Sudent ID: 2 has score of: 80
Sudent ID: 3 has score of: 90
Sudent ID: 4 has score of: 100
1. the objects created and objects stored in the array have different addresses? I was expecting them to match since the object was created on the heap and I'm copying it's pointer.
2. It seems that Creator::getObject() returns the same pointer in all four calls
Address for 1 0x28fe4c
Address for 2 0x28fe4c
Address for 3 0x28fe4c
Address for 4 0x28fe4c
Does that mean that only one object was created? I was expecting 4 different memory address for each object created?