私はコマンドパターンを説明する何かを書いています。私は、この計算機の実装では、すべてのバイナリ演算(加算、減算など)が上位2つのスタック項目に対して演算を単に実行することを認識しているので、そのロジックを別の基本クラス(BinaryCommand )。なぜコンパイラはこのクラスが抽象クラス(C++)だと思いますか?
なぜ私はエラーが表示されているのか混乱しています(下のメイン関数のコメントとして表示されます)。どんな助けでも大歓迎です!
class ExpressionCommand
{
public:
ExpressionCommand(void);
~ExpressionCommand(void);
virtual bool Execute (Stack<int> & stack) = 0;
};
class BinaryCommand : ExpressionCommand
{
public:
BinaryCommand(void);
~BinaryCommand(void);
virtual int Evaluate (int n1, int n2) const = 0;
bool Execute (Stack<int> & stack);
};
bool BinaryCommand::Execute (Stack <int> & s)
{
int n1 = s.pop();
int n2 = s.pop();
int result = this->Evaluate (n1, n2);
s.push (result);
return true;
}
class AdditionCommand : public BinaryCommand
{
public:
AdditionCommand(void);
~AdditionCommand(void);
int Evaluate (int n1, int n2);
};
int AdditionCommand::Evaluate (int n1, int n2)
{
return n1 + n2;
}
int main()
{
AdditionCommand * command = new AdditionCommand(); // 'AdditionCommand' : cannot instantiate abstract class
}