While answering this question I got a bit confused. We all know that this works fine due to the C++ copy semantics:
int *some_obj = new int(42);
int a_copy = *some_obj;
delete some_obj;
printf("The answer is %d\n", a_copy);
But what about this?
int *some_obj = new int(42);
int& a_ref = *some_obj;
delete some_obj;
printf("The answer is %d\n", a_ref);
Is this accessing deleted memory?
Probably asked various times in various forms, but this is not very Google friendly. Hell, I couldn’t make a decent title.
Yes, it is. So that’s not permitted. (You can ensure you see the difference by using a class with a destructor that changes the value.)