I wrote these following codes in Stack.h:
class Stack{
public:
inline bool full();
int size();
inline bool empty();
bool push(const string&);
bool pop(string &s);
bool peek(string &s);
virtual void print();
virtual ~Stack(){}
protected:
vector<string> _elem;
int const _maxsize=10; // line X
};
I got the error:
Stack.h:14: error: ISO C++ forbids initialization of member ‘_maxsize’
Stack.h:14: error: making ‘_maxsize’ static
make: *** [Stack.o] Error 1
if I add a static keyword at line X, and initialize the variable outside the class definition, it could be OK.
But my question is that is there any possible way to declare a non-static const variable and still successfully initialize it???