#include <iostream>
usingnamespace std;
class MyStack{
public:
int size;
int top;;
MyStack();
MyStack(int x, int y) : size(x), top(-1){};
~MyStack(){};
int stack[size];
void push(int x);
int pop();
void display();
};
I am getting error : " invalid use of non-static data member `MyStack::size' "
I don't want to make size as static as i want every instance of this class to set it's own size of stack.
You are trying to declare array of int's based on the size variable which is not known at the compile time. You should never use non-constant variable to declare an array. If you do want to declare an array based on size variable, you should do something like this