不知道哪里错了,求指导

创建一个栈,将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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值