C++ Advanced - 08_05.Calculator. Mr операцията
Здравейте,
задачата ми работи с изключение на mr операцията, толкова време дебъгвах и нищо, не мога да открия причината и да си оправя грешката. Реших да използвам глобален стак за паметта ми(колкото и некоректно да е това и да има и по-хубави начини).
std::stack<int> memory;
class DivideOperation : public Operation {
	std::vector<int> operands;
	int result;
public:
	void addOperand(int operand) override {
		this->operands.push_back(operand);
		if (this->isCompleted()) {
			this->result = this->operands[0] / this->operands[1];
		}
	}
	bool isCompleted() override {
		return this->operands.size() == 2;
	}
	int getResult() override {
		return this->result;
	}
};
class MemorySaveOperation : public Operation {
	std::vector<int> operands;
	int result;
public:
	void addOperand(int operand) override {
		this->operands.push_back(operand);
		if (this->isCompleted()) {
			memory.push(operand);
			this->result = operand;
		}
	}
	bool isCompleted() override {
		return this->operands.size() == 1;
	}
	int getResult() override {
		return this->result;
	}
};
class MemoryReadOperation : public Operation {
	std::vector<int> operands;
	int result;
public:
	void addOperand(int operand) override {
		this->operands.push_back(operand);
		if (this->isCompleted()) {
			this->result = memory.top();
			memory.pop();
		}
	}
	bool isCompleted() override {
		return this->operands.size() == 1;
	}
	int getResult() override {
		return this->result;
	}
};
Къде точно греша в mr оператора? Благодаря предварително !
Много ти благодаря, определено ще я доразгледам!