- Joined
- Sep 5, 2007
- Messages
- 1
- Reaction score
- 0
Here is my code:
It compiles, but run the program, gets segmentation fault. If there is no list<int> vertices, it will be fine. Or if no coding in destructor and keep list<int> vertices, it's no problem too. Any idea?
Code:
#include <iostream>
#include <list>
using namespace std;
struct Cell{
list<int> vertices;
bool counted;
Cell* nextCell;
Cell(){
counted=false;
nextCell=NULL;
}
~Cell(){
Cell* tmp = nextCell;
Cell* current_ptr = nextCell;
while(tmp != NULL){
current_ptr = current_ptr->nextCell;
delete tmp;
tmp = current_ptr;
}
}
};
int main(){
Cell* a = new Cell;
Cell* b = new Cell;
Cell* c = new Cell;
a->nextCell = b;
b->nextCell = c;
delete a;
return 0;
}
It compiles, but run the program, gets segmentation fault. If there is no list<int> vertices, it will be fine. Or if no coding in destructor and keep list<int> vertices, it's no problem too. Any idea?