Sto lavorando su un binario Cerca Albero in C ++. Sto ottenendo i seguenti errori riportati dopo l'esecuzione gdb (Ricevo un segfault) sul mio programma:
#0 0x08049058 in searchTree::tree_node<int>::getLeft (this=0x0) at bst.hxx:75
#1 0x08048ed8 in searchTree::bst_iter<int>::operator++ (this=0xbffff4b4) at bst.hxx:586
#2 0x08048a72 in main () at projectmain.cxx:29
L'errore # 0 si riferisce alla mia funzione getLeft (), che è la seguente:
template <typename T>
inline tree_node<T>* tree_node<T>::getLeft() const
{
return tree_node<T>::left_; //note that left_ is of type tree_node<T>*
}
L'errore # 1 si riferisce al mio operatore ++ definito nei miei iteratori, che è la seguente:
bst_iter<T>& operator++()
{ //note that s is a stack of tree_node<T>*
tree_node<T> *p = pos_->getRight();
s.push(p);
for(p=p->getLeft(); p!=NULL; p=p->getLeft())
{
s.push(p);
}
pos_ = s.top();
s.pop();
return *this;
}
L'errore # 2 si riferisce al mio programma principale, in cui sono incluso il file che contiene le mie definizioni per tree_node, BinaryTree, bst_iter, e bst_citer (che non esiste, a questo punto, quindi non un problema).
bst_iter<int> i = treeTime.begin(); //treeTime is our tree
bst_iter<int> iEnd = treeTime.end();
for(; i != iEnd ;++i) //crash
{
cout<<*i<< ;
}
template <typename T>
inline bst_iter<T> binaryTree<T>::begin()
{
return bst_iter<T>(root_);
}
template <typename T>
inline bst_iter<T> binaryTree<T>::end()
{
return bst_iter<T>(0);
}
Io non sono del tutto sicuro che cosa sta causando l'errore. Credo che ++ () sta cercando di accedere a una zona che non è stato definito, ma io non sono davvero sicuro perché sta facendo che o il modo di fermarlo ... ho provato a tenere indietro sul codice, come il codice è lunga quasi 800 linee, ma se è necessario ulteriori informazioni, fatemelo sapere ...













