У меня пока все есть, и теперь я застрял, не могу придумать, как решить эту проблему. В настоящее время я получаю следующие ошибки:
Код: Выделить всё
Error C2109 subscript requires array or pointer type
Warning C4244 'return': conversion from 'double' to 'int', possible loss of data
Код: Выделить всё
#include
#define STACK_MAX 500
template
class RPNCalculator
{
private:
//Insanciating stack class
T data[STACK_MAX];
int size;
//stack rpnstack;
public:
RPNCalculator() {
size = 0;
}
~RPNCalculator();
int Top() {
if (size == 0) {
fprintf(stderr, "Error: stack empty\n");
return -1;
}
return data[size - 1];
}
void push(T data); // pushes a new operand onto the stack
// the following operations are to be performed as defined for Reverse Polish Notation
// binary operators:
T value(); // returns the topmost value
void pop(); // returns the topmost value and pops it off the top
double add();
double subtract();
double multiply();
double divide();
// unary operators:
double square(); // squares the current value
double negate(); // negates, i.e. 3 becomes -3
bool isEmpty(); // tests to see if there are elements on the stack
void clear(); // clears out the stack
};
template
inline bool RPNCalculator::isEmpty()
{
bool status;
if (!top)
status = true;
else
status = false;
return status;
}
template
void RPNCalculator::clear()
{
}
template
inline RPNCalculator::~RPNCalculator()
{
}
template
inline void RPNCalculator::push(T data)
{
if (size < STACK_MAX)
data[size++] = data;
else
fprintf(stderr, "Error: stack full\n");
}
template
inline T RPNCalculator::value()
{
return T();
}
template
inline void RPNCalculator::pop()
{
if (size == 0)
fprintf(stderr, "Error: stack empty\n");
else
size--;
}
Код: Выделить всё
#include
#include "RPNCalculator.h"
#include
#include
using namespace std;
bool isOperator(const string& input);
void performOperation(const string& st, RPNCalculator& rpnstack);
int main() {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/45776999/c-add-value-into-stack-subscript-requires-array-or-pointer-type-and-warning[/url]