我正在尝试将解决方案上传到OJ,法官使用GCC 我收到了以下错误并且对它们一无所知。
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘{’ token
void insert(int in){
^
In function ‘main’:
error: ‘struct mymultiset_int’ has no member named ‘insert’
x.insert(t);
^
error: ‘struct mymultiset_int’ has no member named ‘getmax’
printf("%d\n",x.getmax());
^
error: ‘struct mymultiset_int’ has no member named ‘_delete’
x._delete(0);
^
我的代码如下所示:
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int t;
#define swap(a,b) t=b,b=a,a=t
/*
when using swap, I use format like swap(x,y); or swap(x,y),
*/
struct mymultiset_int{
int e[100000],end;
void insert(int in){...}
int getmax(){ return e[0]; }
void _delete(int i){...}
}x;
int main(){
x.end=0;memset(x.e,0,sizeof(x.e));
int N,t;scanf("%d",&N);
char i[2];
while (N--){
scanf("%s",i);
if (i[0]=='A'){
scanf("%d",&t);
x.insert(t);
}
else{
printf("%d\n",x.getmax());
x._delete(0);
}
}
}
答案 0 :(得分:1)
你无法在C中定义结构中的函数。
但是在c ++中它是可能的。