Stack ADT

I am working on a project that require us to use stack abstract data type. The program is not complete, this is what I have got so far, but I am not sure what I am doing wrong.
I'm getting this error. Line 39:int 'error undeclared (firts use this function).
Please help me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  
const int STACK_SIZE = 3;
char s[STACK_SIZE];
int top = 1;

class Stack    
{
private:
char s[STACK_SIZE];
int top;
public:
void push(char x);
void pop(char &x);
bool isFull();
bool isEmpty();
Stack() { top = -1; }
};
bool isEmpty()  
{
if (top == -1)
return true;
else
return false;
}
bool isFull()   
{
if (top == (STACK_SIZE-1))
return true;
else
return false;
}
void push(char x) 
{
if (isFull())
{
error(); exit(1);
}
top++; // top is changed first
s[top] = x;
}
void pop(char &x)
{
if (isEmpty())
{
error(); exit(1);
}
x = s[top];
top--;
}

int main()
{....
When defining the member functions you need to specify the class type like this:
1
2
3
4
5
6
7
bool Stack::isEmpty()  
{
	if (top == -1)
		return true;
	else
		return false;
}


Why didn't you use indentation? It makes code so much easier to read :D
Thank you it does work. I add the constructor and is giving me this error Stack::Stack(char)' does not match any in class `Stack'
1
2
3
4
5
Stack::Stack(char size)   //constructer
{
  STACK_SIZE = size;
  top = -1
}
Why o why are you assigning to a global const variable in the constructor???
The error is because you have not declared a Stack constructor that takes a char argument in the class definition.
Topic archived. No new replies allowed.