Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKhatharr

Posted 27 April 2013 - 02:46 PM


Am I freeing ptr1-3, when freeing ptr4?


From what I read in C++ Primer Plus this wouldn't work since ptr2,ptr3, and ptr4 are not considered pointers but ordinary int variables, the statement would have to be:
int* ptr1 = NULL, *ptr2 = NULL, *ptr3 = Null, etc...

 

Aye. Although if we ignore that then the answer is still no:

 

You don't delete pointers. You delete allocations.

 

Also:

 

[attachment=15341:pointing-to-god-1.jpg]


#1Khatharr

Posted 27 April 2013 - 02:36 PM

Another example:
int* ptr1=NULL, ptr2=NULL, ptr3=NULL, ptr4=NULL;
ptr1=new int;
ptr2=ptr1;
ptr3=ptr2;
ptr4=ptr3;
delete ptr4;


Am I freeing ptr1-3, when freeing ptr4?



From what I read in C++ Primer Plus this wouldn't work since ptr2,ptr3, and ptr4 are not considered pointers but ordinary int variables, the statement would have to be:
int* ptr1 = NULL, *ptr2 = NULL, *ptr3 = Null, etc...

 

Aye. Although if we ignore that then the answer is still no:

 

You don't delete pointers. You delete allocations.


PARTNERS