I am traying to code an AVL Tree class in c++ that supports the normal operations for homework.
while trying code the insert
member function I found out that when I debug and put a break point in this member function the debugger goes crazy.
to make sure it is not something that I code wrong I changed the code to this simple one to see what happens:
template<class X,class Y>
void AvlTree<X,Y>::insert(const X& key,const Y& data)
{
if(this==nullptr)
{
std::cout<<"I am null"<<std::endl;
}
std::cout<<"insorted"<<std::endl;
}
It turns out that while running the program:
int main()
{
AvlTree<int,int> tree;
tree.insert(1,1);
}
the insert
function prints "insorted" but while debugging the program and putting a break point on the <<"insorted"<<
it prints "I am null" a lot of times. I don't really get why the this
pointer is null while calling it on a non null tree.
is someone knows what seems to be the problem?