title: C++ : Confused in dealing with multiple classes
body: <p>This is the first time i m trying to handle multiple classes in a c++ program and the experience has been really terrible because i have spent many tens of hours just staring at the code and trying to figure out whats wrong.  Also, my actual code currently is about 600 lines so I will just put up the relevant code to what bothers me the most and try explain it.</p>
  
  <p>I am having a class for a multiway-search-tree called node. And My aim is to use an AVL tree(class name Avlnode) as an index tree(containing words in a sorted order and address of the corresponding node at every Avlnode) in order to do operations on the multi-way-tree in O(log n) time.
  Now consider this code fragment</p>
  
  <pre><code>//Basically searches for a string in Avl tree with root t and returns pointer 
  //to the   corresponding node in the multi-way tree 
  
  node* Avlnode::Avlsearch(string x,Avlnode* t)
  {
      if (t==NULL)
      {
          cout&lt;&lt;"why you search whats not in string";//invalid search
          exit(0);
      }
      else
      {
          if(isLess(x,t-&gt;element)) //isLess compares strings and works good
          {                        //element refers to the string stored in Avlnode
              Avlsearch(x,t-&gt;left);
          }
          else if (isLess(t-&gt;element,x))
          {
              Avlsearch(x,t-&gt;right);
          }
          else
          {
              cout&lt;&lt;"found";  
              cout&lt;&lt;t-&gt;index-&gt;empname;
              return t-&gt;index; //its fine till here
          }
      }
  }
  
  //basically adds child under the boss in multi-way tree, by searching for the
  //address of boss first using the AVL tree
  
  void node::insertunderboss(string child, string boss,Avlnode* obj1)
  {
      node* temp=obj1-&gt;Avlsearch(boss, obj1-&gt;root); //root=root of Avltree
  //why is address of temp and t-&gt;index not the same??
      cout&lt;&lt;temp;
      cout&lt;&lt;"root current is "&lt;&lt;obj1-&gt;root-&gt;element;
      cout&lt;&lt;"\n"&lt;&lt;temp-&gt;empname; //empname is string stored in node
   //this refuses to work even though t-&gt;index-&gt;empname worked perfect.
   // in my first function t-&gt;index-&gt;empname gave me a string
   // I just stored t-&gt;index inside temp
   //But temp-&gt;empname makes cmd hang. Your program has stopped working. 
      node* c=insertemp(child,temp);
      cout&lt;&lt;"last check";
      obj1-&gt;Avlinsert(c,obj1-&gt;root);
      return;
  }
  </code></pre>
  
  <p>I hope my question was clear. I thought of passing by reference but I cannot figure out why this does not work, logically it looks alright.
  Any kind of help would be really appreciated.</p>