I’ve got a class called Task. The header file goes as such:
class Task
{
public:
Task();
//Methods Declarations
private:
int uid;
list<Task> l;
friend ostream & operator<<(ostream & os, const Task &t);
friend ostream & operator<<(ostream & os, const list<Task *> &l);
};
Now in my main file, I run:
Task * tasks[7];
for (int i = 0; i != 7; ++i)
tasks[i] = new Task();
delete [] *tasks;
upon running delete[] *tasks; I get the error message below:
Assignment 4(23901) malloc: *** error for object 0x1001009f8: pointer being
freed was not allocated *** set a breakpoint in
malloc_error_break to debug
As soon as I comment out list < Task *> l, and re-run it, the error message goes away. I tried changing list < Task * > l, to list < Task > l, but to no avail.
I can’t figure it out. Why would it error out, when list < Task > is allocated on the stack (well pointers to heap elements)? (STL management). Also tried vector<int>. I get the same thing.
UPDATE: delete tasks[i] didn’t do the trick.
You don’t use
but