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
};
エラーが発生しました:
Stack.h:14: error: ISO C++ forbids initialization of member ‘_maxsize’
Stack.h:14: error: making ‘_maxsize’ static
make: *** [Stack.o] Error 1
X行目に静的キーワードを追加し、クラス定義の外部で変数を初期化すると、問題ない可能性があります。
しかし、私の質問は、非静的const変数を宣言し、それでも正常に初期化する方法はありますか?