该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
请各位高手看下这代码怎么有问题了,明明申明了变量怎么VC6.0上老是提示"undeclared identifier"
const int maxstack=20;//stack.h
typedef int Stack_entry;
enum Error_code{success,underflow,overflow};
class Stack
{
public:
Stack();
Error_code push(const Stack_entry &item);
Error_code pop();
Error_code top(Stack_entry &item)const;
bool empty()const;
protected:
int count;
Stack_entry entry[maxstack];
};
class Extended_stack:public Stack
{
public:
bool full()const;
int size()const;
void print();
void clear();
Error_code stack_copy(Extended_stack &source);
};
#include"stack.h"//stack.cpp
Stack::Stack()
{
count=0;
}
bool Stack::empty()const
{
return(count==0);
}
bool Extended_stack::full()const
{
return(count==maxstack);
}
Error_code Stack::push(const Stack_entry &item)
{
if(count>=maxstack)
return overflow;
entry[count]=item;
count++;
return success;
}
Error_code Stack::pop()
{
if(count<=0)
return underflow;
count--;
return success;
}
Error_code Stack::top(Stack_entry &item)const
{
if(count<=0)
return underflow;
item=entry[count-1];
return success;
}
int Extended_stack::size()
{
return count;
}
void Extended_stack::print()
{
if(count==0)
cout<
else
{
int i;
cout<
for(i=count-1;i>=0;i--)
cout<
}
}
void Extended_stack::clear()
{
count=0;
}
Error_code Extended_stack::stack_copy(Extended_stack &source)
{
if((maxstack-count)<=source.count)
return overflow;
else
{
int i,t;
desk.count=source.count;
for(i=count-1,t=0;i
{
entry[i]=source.entry[t];
count++;
}
}
return success;
}
typedef int Stack_entry;//test.cpp
#include"iostream"
using namespace std;
#include"stack.h"
int main()
{
void introduction();
char get_command();
bool do_command(char c,Stack &test_stack);
Extended_stack test;
Extended_stack test_stack;
introduction();
while(do_command(get_command(),test_stack));
return 0;
}
void introduction()
{
cout<
<
<
<
<
<
<
<
<
<
<
}
char get_command()
{
char c;
cout<
cin>>c;
return c;
}
bool do_command(char c,Extended_stack &test_stack)
{
bool continue_input=true;
Stack_entry x;
if(c>=65&&c<=90)c=c+32;
switch(c)
{
case 'i':
if(test_stack.full())
cout<
else
{
cout<
cin>>x;
test_stack.push(x);
}
break;
case 's':
if(test_stack.top(x)==underflow)
cout<
else
cout<
break;
case 'd':
if(test_stack.pop()==underflow)
cout<
else
cout<
break;
case 'p':
cout<
test_stack.print();
break;
case '#':
cout<
break;
case 'r':
test_stack.clear();
cout<
break;
case 'c':
test.stack_copy(test_stack);
cout<
test.print();
break;
case 'q':
continue_input=false;
break;
}
return continue_input;
}