Question relating to delete.

What is the point in delete beany.str? I thought deletion was only to be used with "new" dynamic memory?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
#include <cstring> // for strlen(), & strcpy();
struct stringy
{
    char * str;
    int ct;
};
int main()
{
    ....
    ...
    delete [] beany.str;
    return 0;
}
Last edited on
Are you sure there wasn't a new in .... part? If there wasn't, unless str was initialized to 0, this should segfault.
It was actually a student's code and I often look to him for advice. I wasn't sure why he put that in there because there was no previous new and wasn't sure if I was missing some sort of functionality for the delete feature.
Topic archived. No new replies allowed.