title: Debug Assertion Failed! Expression: is_block_type_valid(header->_block_use)
body: <pre><code>Debug Assertion Failed!
  
  Program: ...nts\Visual Studio 2015\Projects\Project 5\Debug\Project 5.exe
  File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
  Line: 892
  
  Expression: is_block_type_valid(header-&gt;_block_use)
  
  For information on how your program can cause an assertion
  failure, see the Visual C++ documentation on asserts.
  
  (Press Retry to debug the application)
  </code></pre>
  
  <p>The program runs and outputs everything correctly, and throws this error. I haven't been able to find any good explanations of what this means or how to go about finding or fixing it. Here is a complete copy of the (incredibly ugly and badly written) code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  /* a class for storing a Binary Tree */
  template &lt;class Type&gt;
  class BinaryTree {
  protected:
      Type parentArray[10];
      Type childArray[10];
  public:
      BinaryTree();
      BinaryTree(int&amp; k);
      ~BinaryTree();
      BinaryTree(BinaryTree&lt;Type&gt;&amp; bt);
      void operator= (BinaryTree&lt;Type&gt;&amp; bt);
      friend ostream&amp; operator&lt;&lt; (ostream&amp; s, BinaryTree&lt;Type&gt; bt) {
          s &lt;&lt; "[ ";
          bt.inorder(bt.getRoot());
          s &lt;&lt; "]" &lt;&lt; endl;
          return s;
      };
      int size();
      int height();
      int getLeft(int k);
      int getRight(int k);
      void preorder(int k);
      void inorder(int k) {
  
          // do I have a left child?
          if ((getLeft(k)) != -1) {
              // if yes inorder (left child)
              inorder(getLeft(k));
          };
          // output k
          cout &lt;&lt; k &lt;&lt; " ";
          // do I have a right child?
          if ((getRight(k)) != -1) {
              // if yes inorder (right child)
              inorder(getRight(k));
          };
      };
      void postorder(int k);
      void setRoot(Type&amp; val);
      void setParent(Type* child, Type* parent);
      void setLeft(Type&amp; val);
      void setRight(Type&amp; val);
      int getRoot();
  };
  
  /* default constructor */
  template &lt;class Type&gt;
  BinaryTree&lt;Type&gt;::BinaryTree() {
      parentArray = new ArrayClass&lt;Type&gt;();
      childArray = new ArrayClass&lt;Type&gt;();
  };
  
  /* non-empty constructor */
  template &lt;class Type&gt;
  BinaryTree&lt;Type&gt;::BinaryTree(int&amp; k) {
  //  parentArray = new Type[k];
  //  childArray = new Type[k];
  };
  
  template &lt;class Type&gt;
  BinaryTree&lt;Type&gt;::~BinaryTree() {
      delete[] parentArray;
      delete[] childArray;
  };
  
  template &lt;class Type&gt;
  BinaryTree&lt;Type&gt;::BinaryTree(BinaryTree&lt;Type&gt;&amp; bt) {
      for (int i = 0; i &lt; bt.size(); i++) {
          parentArray[i] = bt.parentArray[i];
          childArray[i] = bt.childArray[i];
      };
  };
  
  template &lt;class Type&gt;
  void BinaryTree&lt;Type&gt;::operator= (BinaryTree&lt;Type&gt;&amp; bt) {
  
  };
  
  
  /* return the size of the tree using the length of the parent array */
  template &lt;class Type&gt;
  int BinaryTree&lt;Type&gt;::size() {
  
      return (sizeof(parentArray)/sizeof(*parentArray));
  };
  
  
  template &lt;class Type&gt;
  int BinaryTree&lt;Type&gt;::height() {
      return 5;
  };
  
  template &lt;class Type&gt;
  int BinaryTree&lt;Type&gt;::getLeft(int k) {
  
      // if the parent array value of the given number is k and 
      // the child array value indicates it is a left child
      for (int i = 0; i &lt; size(); i++) {
          if ((parentArray[i] == k) &amp;&amp; (childArray[i] == 0)) {
  
              // return that value
              return i;
          };
      };
      return -1;
  };
  
  template &lt;class Type&gt;
  int BinaryTree&lt;Type&gt;::getRight(int k) {
  
      // if the parent array value of the given number is k and 
      // the child array value indicates it is a right child
      for (int i = 0; i &lt; size(); i++) {
          if ((parentArray[i] == k) &amp;&amp; (childArray[i] == 1)) {
  
              // return that value
              return i;
          };
      };
      return -1;
  };
  
  template &lt;class Type&gt;
  void BinaryTree&lt;Type&gt;::preorder(int k) {
      // output k
      cout &lt;&lt; k &lt;&lt; " ";
      // do I have a left child?
      if ((getLeft(k)) != -1) {
          // if yes preorder left child
          preorder(getLeft(k));
      };
      // do I have a right child?
      if ((getRight(k)) != -1) {
          // if yes preorder right child
          preorder(getRight(k));
      };
  };
  
  template &lt;class Type&gt;
  void BinaryTree&lt;Type&gt;::postorder(int k) {
      // do I have a left child?
      if ((getLeft(k)) != -1) {
          // if yes inorder (left child)
          inorder(getLeft(k));
      };
      // do I have a right child?
      if ((getRight(k)) != -1) {
          // if yes inorder (right child)
          inorder(getRight(k));
      };
      // output k
      cout &lt;&lt; k &lt;&lt; " ";
  };
  
  template &lt;class Type&gt;
  void BinaryTree&lt;Type&gt;::setRoot(Type&amp; val) {
      // if the given value is the root of the tree then set
      // its index in the parent and child arrays to -1
      parentArray[val] = -1;
      childArray[val] = -1;
  };
  
  template &lt;class Type&gt;
  void BinaryTree&lt;Type&gt;::setParent(Type* child, Type* parent) {
  
      // set a given value as the parent of a given value
      parentArray[(*child)] = *parent;
  };
  
  template &lt;class Type&gt;
  void BinaryTree&lt;Type&gt;::setLeft(Type&amp; val) {
  
      // set a given value in the child array to indicate a left child
     childArray[val] = 0;
  };
  
  template &lt;class Type&gt;
  void BinaryTree&lt;Type&gt;::setRight(Type&amp; val) {
  
      // set a given value in the child array to indicate a right child
      childArray[val] = 1;
  };
  
  template &lt;class Type&gt;
  int BinaryTree&lt;Type&gt;::getRoot() {
  
      // find the root value of the tree
      for (int i = 0; i &lt; size(); i++) {
          if (parentArray[i] == -1) {
  
              // and return it
              return i;
          };
      };
  };
  
  int  main() {
      int* val1 = new int;
      int* val2 = new int;
      int* val3 = new int;
      int count;
  
      cin &gt;&gt; count;
  
      BinaryTree&lt;int&gt; bt(count);
  
      for (int i = 0; i &lt; count; i++) {
          cin &gt;&gt; *val1;
          cin &gt;&gt; *val2;
          cin &gt;&gt; *val3;
  
          if (i == 0) {
              bt.setRoot(*val1);
          };
  
          if (*val2 != -1) {
              bt.setParent(val2, val1);
              bt.setLeft(*val2);
          }
          if (*val3 != -1) {
              bt.setParent(val3, val1);
              bt.setRight(*val3);
          }
  
          val1 = new int;
          val2 = new int;
          val3 = new int;
      };
  
      cout &lt;&lt; bt.size() &lt;&lt; endl;
      bt.postorder(bt.getRoot());
      cout &lt;&lt; endl;
      bt.preorder(bt.getRoot());
      cout &lt;&lt; endl;
  
      delete val1;
      delete val2;
      delete val3;
  };
  </code></pre>
  
  <p>Some of the functions in the BinaryTree class aren't finished yet and just have filler garbage in them for testing.</p>