in this code as you can see used DMA and deleted p but the p[0] is still accessable. how is this possible.
or am i missing something
#include<iostream>
using namespace std;
int i = 0;
class T {
public:
int id;
T() {
i++;
id = i;
cout << "Created: " << id << endl;
}
~T() {
cout << "Deleted: " << id << endl;
}
};
int main() {
T *p = new T[10];
delete p;
cout << "Id: " << p[0].id; // how it is still accessable
}
output
Created: 1
Created: 2
Created: 3
Created: 4
Created: 5
Created: 6
Created: 7
Created: 8
Created: 9
Created: 10
Deleted: 1
Id: 1