I was wondering how this piece of code gives a memory access violation?
{
Vector3f *a = new Vector3f [10];
Vector3f *b = a;
b[9] = Vector3f (2,3,4);
delete[] a;
a = new Vector3f [10];
b[4] = Vector3f (1,2,3);
delete[] a;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
bstill points to the same array asawhen you calldelete[] a, and then you try to use that memory withb[4].