gpt4 book ai didi

c++ - 错误 : cannot convert parameters from 'int [10]' to 'int'

转载 作者:太空宇宙 更新时间:2023-11-04 14:35:54 25 4
gpt4 key购买 nike

<分区>

这是一个相当简单的 Stack 实现程序。但是push()pop()display() 函数的声明有问题。错误陈述如下。请帮我找出问题所在。

错误:

error C2664: 'push' : cannot convert parameter 1 from 'int [10]' to 'int'
error C2664: 'pop' : cannot convert parameter 1 from 'int [10]' to 'int'
error C2664: 'display' : cannot convert parameter 1 from 'int [10]' to 'int'

程序:

#include<iostream>
#define STACKSIZE 10
using namespace std;
void push(int,int,int);
void pop(int,int);
void display(int,int);
int main()
{
int stack[STACKSIZE],n,data,stackptr=-1;
while(1)
{
cout<<"1. Push\n2. Pop\n3. Display\n4. Exit\n";
cin>>n;
switch(n)
{
case 1:
cout<<"\nEnter a data to push: ";
cin>>data;
push(stack,stackptr,data);
break;
case 2:
pop(stack, stackptr);
break;
case 3:
display(stack, stackptr);
break;
case 4:
exit(1);
break;
default:
cout<<"\nEnter correct choice...\n\n";
}
}
system("pause");
return 0;
}
void display(int stack[STACKSIZE], int &stackptr)
{
cout<<"\n\n";
for(int i=0;i<stackptr;i++)
cout<<stack[i]<<"\n";
cout<<"\n\n";
}
void push(int stack[STACKSIZE],int &stackptr, int data)
{
if(stackptr == STACKSIZE - 1)
{
cout<<"\n\nStack full\n\n";
return ;
}
stackptr++;
stack[stackptr] = data;
}
void pop(int stack[STACKSIZE], int &stackptr)
{
if(stackptr == 0)
{
cout<<"\n\nStack Empty\n\n";
return ;
}
stackptr = stackptr-1;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com