STL list

Joined
Sep 5, 2007
Messages
1
Reaction score
0
Here is my code:

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top