segmentation error

why am i getting an segmentation error here

1
2
3
4
5
6
7
8
9
10
void Tree::printTreeList()
{
	unsigned int i;
	cout << treeVector.back()->getName();
	cout << "\n\n\n LISTING \n";
	for (vector<TreeElement*>::iterator it = treeVector.begin(); it!=treeVector.end(); ++it)
	{
        cout << (*it)->getName()<< endl;
    }
}


note1: that when i run the code, the line cout << treeVector.back()->getName(); works, the problem is in the for loop.

note2: when i run the code with only the following code in the for loop cout << *it<< endl;, i get the following output
w


 LISTING 
0
0x99260f8
0x99260a8
0x9926108
0
0x99260f8
0x99260a8

i think this means that there are pointers that dont point to any memory

the weird thing is that when the objects are made, all the pointers do point to some memory and that position 4 and 0 allways become 0
this is the output when the pointers are made
FILE; SystemTree.cbp   0x991e018
FILE; SystemTree.depend   0x9926098
DIR; src   0x9926070
DIR; obj   0x99260f8
FILE; SystemTree.layout   0x99260d0
DIR; bin   0x99260a8
DIR; include   0x9926108

Last edited on
Notice that you added 7 TreeElements all with unique addresses but you only have 3 valid addresses printing out in Treeprint?
What happen to the other 4? One was turned into 0 (NULL) the others are gone.
Topic archived. No new replies allowed.