I cannot figure out these errors can someone please help
error C2065: 'stack' : undeclared identifier
error C2228: left of '.isEmptyStack' must have class/struct/union type
error C2228: left of '.pop' must have class/struct/union type
error C2228: left of '.push' must have class/struct/union type
error C2228: left of '.top' must have class/struct/union type
error C3861: 'stack': identifier not found, even with argument-dependent lookup
here is my code
#include <iostream>
using namespace std;
#ifndef H_stackType
#define H_stackType
template<class Type>
class stackType
{
public:
const stackType<Type>& operator=(const stackType<Type>&);
void initializeStack();
bool isEmptyStack();
bool isFullStack();
void push(const Type& newItem);
Type top();
void pop();
stackType(int stackSize = 100);
~stackType();
private:
int maxStackSize;
int stackTop;
Type *list;
};
#endif
#include "stackType.h"
#include <iostream>
using namespace std;
template<class Type>
void stackType<Type>::initializeStack()
{
stackTop = 0;
}
template<class Type>
bool stackType<Type>::isEmptyStack()
{
return(stackTop == 0);
}
template<class Type>
bool stackType<Type>::isFullStack()
{
return(stackTop == maxStackSize);
}
template<class Type>
void stackType<Type>::push(const Type& newItem)
{
if (stackTop < stackSize - 1)
{
++stackTop;
list[stackTop] = newItem;
}
else
cerr<<"Cannot add to a full stack."<<endl;
}
template<class Type>
Type stackType<Type>::top()
{
assert(stackTop != 0);
return list[stackTop - 1];
}
template<class Type>
void stackType<Type>::pop()
{
if (stackTop >= 0)
stackTop--;
else
cerr<<"Cannot remove from an empty stack."<<endl;
}
template<class Type>
stackType<Type>::stackType(int stackSize)
{
if(stackSize <= 0)
{
cerr<<"Size of the array to hold the stack must "
<<"be positive."<<endl;
cerr<<"Creating an array of size 100."<<endl;
maxStackSize = 100;
}
else
maxStackSize = stackSize;
stackTop = 0;
list = new Type[maxStackSize];
assert(list != NULL);
}
template<class Type>
stackType<Type>::~stackType()
{
delete [] list;
}
#include <iostream>
#include <string>
#include <cassert>
#include "stackType.h"
using namespace std;
string RPN(string infix);
int main()
{
string infix;
stackType<string> stack(100);
cout << "NOTE: Enter ! for infix expression to exit." << endl;
for (;;)
{
cout << "Infix Expression? ";
getline(cin, infix);
if (infix == "!") break;
cout << "RPN Expression is: " << RPN(infix) << endl;
}
return 0;
}
string RPN(string infix)
{
char topToken;
string RPNexp;
const string BLANK = " ";
for (unsigned i = 0; i < infix.length(); i++)
{
switch(infix[i])
{
case ' ' : break;
case '(' : stack.push(infix[i]);
break;
case ')' : for (;;)
{
assert (!stack.isEmptyStack());
topToken = stack.top();
stack.pop();
if (topToken == '(') break;
RPNexp.append(BLANK + topToken);
}
break;
case '+' : case '-' :
case '*' : case '/' :
for (;;)
{
if (stack.isEmptyStack() ||
stack.top() == '(' ||
(infix[i] == '*' || infix[i] == '/') &&
(stack.top() == '+' || stack.top() == '-')
)
{
stack.push(infix[i]);
break;
}
else
{
topToken = stack.top();
stack.pop();
RPNexp.append(BLANK + topToken);
}
}
break;
default : RPNexp.append(BLANK + infix[i]);
}
}
for (;;)
{
if (stack.isEmptyStack()) break;
topToken = stack.top();
stack.pop();
if (topToken != '(')
{
RPNexp.append(BLANK + topToken);
}
else
{
cout << "Error in infix expression";
break;
}
}
return RPNexp;
}