title: Dynamic Stack Memory Reallocation
body: <p>I'm fairly new to C++ and new to pointers as well. I'm currently working on a stack and was trying to reallocate the memory for the stack as the size of the stack reaches the top however, I'm running into issues. I've already done a lot of research both on Google and stack overflow and have found some information helpful but since I'm so new to stacks and C++ I'm still having issues. I was hoping some bright and intelligent people could at least point me in the right direction.</p>
  
  <p>now... Here's my code. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #define STACKMAX 20
  using namespace std;
  
  template &lt;class T&gt; class StackTemplated {
  private:
      int top;
      T   values[STACKMAX];
  public:
      StackTemplated();
      void    push(T i);
      T       pop(void);
      bool    empty(void);
   }; 
  
  
  template &lt;class T&gt; StackTemplated&lt;T&gt;::StackTemplated() {
      top = -1;
  }
  
  template &lt;class T&gt;void StackTemplated&lt;T&gt;::push(T i) {
  if (top == STACKMAX - 1) {
  
      // reallocate top of stack. (this is the area I'm having issues)
      char * string1;
      string1 = (char *)calloc(STACKMAX, sizeof(char));
  
          if (top == STACKMAX - 1) {
              cout &lt;&lt; "The stack didn't re-allocate.";
              exit(1);
          }
  
  } else {
      top++;
      values[top] = i;
  }
  }   
  
   template &lt;class T&gt; T StackTemplated&lt;T&gt;::pop(void) {
  if (top &lt; 0) {
      printf("%", "Stack underflow!");
      exit(1);
  } else {
      return values[top--];
  }
  }   
  
  template &lt;class T&gt; bool StackTemplated&lt;T&gt;::empty() {
  return (top == -1);
  }
  </code></pre>