title: C++ how to reach 'stack' behaviour in this code?
body: <p>I would like to ask 2 question about this code. Where I just try to simulate a stack.</p>
  
  <p>Stack.h</p>
  
  <pre><code> #pragma once
  
  namespace stackandqueue {
  
      class Stack
      {
      private:
          int index;
          int *stackdata;
  
      public:     
          Stack();    
          ~Stack();
          void push(int val);
          int pop();
          int top();
          bool isEmpty();
      };
  
  }
  </code></pre>
  
  <p>Stack.cpp</p>
  
  <pre><code>#include "stdafx.h"
  #include "Stack.h"
  
  namespace stackandqueue {
  
          Stack::Stack() : index{ 0 }
          {
              stackdata = new int[index];
          }
          Stack::~Stack()
          {
              delete[] &amp;stackdata;
          }
          void Stack::push(int val) {
              stackdata[index] = val;
              index++;
          }
          int Stack::pop() {
              int val = stackdata[index];
              index--;
              return val;
          }
          int Stack::top() {
              return stackdata[index];
          }
          bool Stack::isEmpty() {
              return index == 0;
          }
  }
  </code></pre>
  
  <p>Meaning is to let me create</p>
  
  <pre><code> Stack stack;
  </code></pre>
  
  <p>And then it initilizes a dynamic array with 0 as first index and  that let me push, pop, top values.</p>
  
  <p>First question:
  Why am I having unresolved symbols for method definitions?</p>
  
  <p>Second question:
  About 'stackdata', you find is the right way if I want to declare an "array" with dynamic size for this behaviour? </p>
  
  <p>I'm open for improvements and best practices. Im used to programming languagesbut I've never delved into c ++ and I don't want to have bad practices. So you see I am taking it from the begining.</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p><em>I post solution reached with your help that maybe helps someone.</em></p>
  
  <pre><code>class Stack
      {
      private:
          int index;
          int* stackdata;
  
      public:     
          Stack(int size);    
          ~Stack();
          void push(int val);
          int pop();
          int top();
          bool isEmpty();
      };
  
      Stack::Stack(int size) 
          : index {0}, stackdata{new int[size]} 
          {
          }
          Stack::~Stack()
          {
              delete[] stackdata;
          }
          void Stack::push(int val) {
              stackdata[index] = val;
              index++;
          }
          int Stack::pop() {
              index--;
              return stackdata[index];
          }
          int Stack::top() {
              return stackdata[index-1];
          }
          bool Stack::isEmpty() {
              return index == 0;
          }
  </code></pre>