Absolutely, delete should have been applied. So rather than:
Code:
int main(int argc, char *argv[])
{
struct node *first;
first = new struct node;
first->name ="Hi there";
cout << first->i;
}
Which neglects the proper book keeping, one should release the memory from the heap prior to to leaving the main function's scope, and it is usually prudent to test that the allocation was successful. Thus a proper implementation would read:
Code:
int main(int argc, char *argv[])
{
struct node *first;
first = new struct node;
if(NULL == first)
{
// error handling for failed memory allocation....
cout << "Memory was not allocated." << endl;
return 1;
}
first->name ="Hi there";
cout << first->i;
delete first;
return 0;
}
I apologize about missing that in the previous post.
Best Regards,
New Ink