I am learning C++ and I am have written some code to get some experience with manually creating and removing objects. I don't think I fully understand the semantics of delete because the print statement still prints 3 and I believe it shouldn't.
Code
#include <iostream>
class Test {
public:
int x;
int y;
};
using namespace std;
int main() {
Test t1;
t1.x = 1;
t1.y = 2;
cout << t1.x << endl;
cout << t1.y <<endl;
Test *t2 = new Test();
t2->x = 3; t2->y = 4;
cout << t2->x << endl;
cout << t2->y <<endl;
delete t2;
cout << t2->x << endl;
}
Output
joel-MacBook-Air:src joel$ ./test
1
2
3
4
3
Please could you explain why it prints 3 at the very end? My knowledge is that it shouldn't print 3 as I deleted the object.