不知道哪里错了,求指导!O(∩_∩)O谢谢~
创建一个栈,将10、12、14入栈,输出栈顶元素,然后退栈,代码如下#include<iostream.h>
const int size=10;
class stack
{
int stck[size];
int tos;
public:
stack(int tos)
{tos=0;};
void push(int ch);
int pop();
}
void stack::push(int ch)
{
if(tos==size)
cout<<"stack is full\n"<<endl;
stack[tos]=ch;
tos++;
}
int stack::pop()
{
if(tos==0)
cout<<"stack is empty\n"<<endl;
tos--;
return stck[tos];
}
void main()
{
stack s1;
int i;
s1.push(10);
s1.push(12);
s1.push(14);
for(i=0;i<3;i++)
cout<<"stack s1"<<s1.pop()<<"\n";
}
错误如下,,奈何看不懂。。。求指点!!
E:\123\P290 Q5.CPP(14) : error C2628: 'stack' followed by 'void' is illegal (did you forget a ';'?)
E:\123\P290 Q5.CPP(15) : error C2556: 'class stack __thiscall stack::push(int)' : overloaded function differs only by return type from 'void __thiscall stack::push(int)'
E:\123\P290 Q5.CPP(10) : see declaration of 'push'
E:\123\P290 Q5.CPP(15) : error C2371: 'push' : redefinition; different basic types
E:\123\P290 Q5.CPP(10) : see declaration of 'push'
E:\123\P290 Q5.CPP(18) : error C2143: syntax error : missing ';' before '['
E:\123\P290 Q5.CPP(18) : error C2143: syntax error : missing ';' before '['
E:\123\P290 Q5.CPP(32) : error C2512: 'stack' : no appropriate default constructor available
E:\123\P290 Q5.CPP(34) : error C2264: 'push' : error in function definition or declaration; function not called
E:\123\P290 Q5.CPP(35) : error C2264: 'push' : error in function definition or declaration; function not called
E:\123\P290 Q5.CPP(36) : error C2264: 'push' : error in function definition or declaration; function not called
Error executing cl.exe.