How do you delete a pointer without deleting the data the pointer points to?

Posted by Faken on Stack Overflow See other posts from Stack Overflow or by Faken
Published on 2010-05-07T20:40:35Z Indexed on 2010/05/07 20:48 UTC
Read the original article Hit count: 173

Filed under:
|

I have a pointer that points to an array and another pointer referencing the same array. How do i delete any one of those pointers without killing the array such that the second undeleted pointer still works?

for example:

int* pointer1 = new int [1000];
int* pointer2;
pointer2 = pointer1;

Now i want to get rid of pointer1, how would i do it such that i can continue to access the array normaly through pointer2?

© Stack Overflow or respective owner

Related posts about pointers

Related posts about c++