title: I am having a problem with Struct identifier is undefined and incompatible declarations for funtions on AVL tree program
body: <p>This is the header file for an AVL tree program using a struct. The other private member functions are in my BinaryTree.cpp file and there are no issues there. However, I have discussed further below in the code the issue I am having. Any help or suggestions will be appreciated!
  #ifndef BINARYTREE_H
  #define BINARYTREE_H</p>
  <pre><code>#include&lt;cstdio&gt;
  #include&lt;sstream&gt;
  #include&lt;algorithm&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  
  class BinaryTree
  {
  private:
      struct TreeNode
      {
          string name;
          int krabbyPatty;
          TreeNode* left;
          TreeNode* right;
  
      };
  
      TreeNode* root;
      
      // Private member functions
      void insert(TreeNode *&amp;, TreeNode *&amp;);
      void destroySubTree(TreeNode *);;
      void displayInOrder(TreeNode *) const;
      void display(TreeNode *ptr, int level);
      void getTotal(TreeNode *nodePtr, int &amp;total);
      void getMost(TreeNode *nodePtr, string&amp; n, int&amp; mostPatties);
      void getLeast(TreeNode *nodePtr, string&amp; n, int&amp; leastPatties);
  
  
  public:
      // Constructor
      BinaryTree()
      { 
  
          root = NULL; 
      
      }
  
      // Destructor
      ~BinaryTree()
      { 
          destroySubTree(root); 
      }
  
      // Binary tree operations
      void insertNode(string, int);
      int searchNode(string);
      //void remove(string);
  
      void displayInOrder() const
      {  
          displayInOrder(root); 
      }
      
      void getLeastNumPatties(string&amp;, int&amp;);
      void getMostNumPatties(string&amp;, int&amp;);
      int getTotalNumPatties();
      void displayTree();
  
      int height(TreeNode *);
      int diff(TreeNode *);
      
      TreeNode r_rotation(TreeNode *);
      TreeNode *l_rotation(TreeNode *);
      TreeNode *lr_rotation(TreeNode *);
      TreeNode *rl_rotation(TreeNode *);
      
      TreeNode* balance(TreeNode *);
  
  
  };
  
  
  /*  height:  Find the height of a node and return it    */
  int BinaryTree::height(TreeNode *temp) 
  {
  //WRITE DEFINITION
  int h = 0;
  if (temp != NULL)
  {
      int l_height = height(temp-&gt;left);
      int r_height = height(temp-&gt;right);
      int max_height = max(l_height, r_height);
      h = max_height + 1;
  }
  return h;
  }
  
  
  /*  diff:  Find the HEIGHT DIFFERENCE between the left &amp; right subtrees */
  int BinaryTree::diff(TreeNode *temp)
  {
  //WRITE DEFINITION
  int l_height = height(temp-&gt;left);
  int r_height = height(temp-&gt;right);
  int b_factor= l_height - r_height;
  return b_factor;
  }
  </code></pre>
  <p>The problems begin right here, the error is that TreeNode is undefined and the function name says declaration is incompatible with &quot;BinaryTree::TreeNode *BinaryTree::l_rotation(BinaryTree::TreeNode *)&quot; And this problem is the same for every function from this point on, so I can rinse and repeat to fix the rest. I know this is probably something simple that I am just looking over, however, any help will be appreciated!</p>
  <pre><code>/*  l_rotation:  Perform LEFT ROTATION on this parent node  */              
  TreeNode *BinaryTree::l_rotation(TreeNode *parent)
  {
  //WRITE DEFINITION
  TreeNode *temp;
  temp = parent-&gt;left;
  parent-&gt;right = temp-&gt;left; //SWITCHING TEAMS (if node exists, NULL otherwise)
  temp-&gt;left = parent;  //new parent node (move old parent to left)
  return temp;
  }
  
  /*  r_rotation:  Perform RIGHT ROTATION on this parent node */
  TreeNode *BinaryTree::r_rotation(TreeNode *parent)
  {
  TreeNode *temp;
  temp = parent-&gt;right;
  parent-&gt;right = temp-&gt;left;
  temp-&gt;left = parent;
  return temp;
  }
  
  
  TreeNode *BinaryTree::lr_rotation(TreeNode *parent)
  {
  TreeNode *temp;
  temp = parent-&gt;left;
  parent-&gt;left = r_rotation(temp);
  return r_rotation(parent);
  }
  
  /*  rl_rotation:  Perform RIGHT-LEFT ROTATION on this parent node   */
  TreeNode *BinaryTree::rl_rotation(TreeNode *parent)
  {
  //WRITE DEFINITION
  TreeNode *temp;
  temp = parent-&gt;right;
  parent-&gt;right = l_rotation(temp);
  return l_rotation(parent);
  }
  
  
  TreeNode *BinaryTree::balance(TreeNode *temp)
  {
  //WRITE DEFINITION
   int bal_factor = diff (temp);
  if (bal_factor &gt; 1)
  {
      if (diff(temp-&gt;left()) &gt; 0)  // 2, 1  RIGHT
      {
          temp = r_rotation(temp);
          cout &lt;&lt; &quot;\nRIGHT rotation&quot;;
      }
      else                            // 2, -1 LEFT-RIGHT
      {
          temp = lr_rotation(temp);
          cout &lt;&lt; &quot;\nLEFT-RIGHT rotation&quot;;
      }
  }
  else if (bal_factor &lt; -1)
  {
      if (diff (temp-&gt;right) &gt; 0) // -2, 1 RIGHT-LEFT
      {
          temp = rl_rotation(temp);
          cout &lt;&lt; &quot;\nRIGHT-LEFT rotation&quot;;
      }
      else                            // -2, -1 LEFT
      {
          temp = l_rotation(temp);
          cout &lt;&lt; &quot;\nLEFT Rotation&quot;;
      }
  }
  return temp;
  
  }
  
  
  
  
  
  #endif
  </code></pre>