What is better: to delete pointer or set it with a new value?

Posted by user63898 on Stack Overflow See other posts from Stack Overflow or by user63898
Published on 2010-05-31T07:49:52Z Indexed on 2010/05/31 12:43 UTC
Read the original article Hit count: 127

Filed under:
|

Hi simple question in c++ , say i have a loop and i have function that returns pointer to item
so i have to define inner loop pointer so my question is what to do with the pointer inside the loop , delete it ? or to set it with new value is good
for example:

for(int i =0;i<count();i++)
{

 ptrTmp* ptr = getItemPtr();
 // do somthing with the ptr ...
 // what to do here ? to delete the poinetr or not? 
 delete ptr;  // ??

}

© Stack Overflow or respective owner

Related posts about c++

Related posts about pointers