커맨드 패턴을 설명하기 위해 뭔가를 쓰고 있습니다. 나는이 계산기 구현을 위해 모든 2 진 연산 (더하기, 빼기 등)이 상위 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
}