关于函数指针的问题

来源:百度知道 编辑:UC知道 时间:2024/06/15 05:23:51
下面程序在VC++ 6.0上运行出错
#include<stdio.h>
int max(int a,int b){
if(a>b)return a;
else return b;
}
main(){
int max(int a,int b);
int(*pmax)();
int x,y,z;
pmax=max;
printf("input two numbers:\n");
scanf("%d%d",&x,&y);
z=(*pmax)(x,y);
printf("maxmum=%d",z);
}

E:\c代码\345.cpp(11) : error C2440: '=' : cannot convert from 'int (__cdecl *)(int,int)' to 'int (__cdecl *)(void)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
E:\c代码\345.cpp(14) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
E:\c代码\345.cpp(16) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

345.obj - 1 error(s), 0 warning(s)

哪里错了阿

#include<stdio.h>
int max(int a,int b){
if(a>b)return a;
else return b;
}
main(){
int max(int a,int b);
int(*pmax)(int a,int b);//int(*pmax)();
int x,y,z;
pmax=max;//这里报错,但错在pmax的声明,应该修改为int(*pmax)(int a,int b);
printf("input two numbers:\n");
scanf("%d%d",&x,&y);
z=(*pmax)(x,y);
printf("maxmum=%d",z);
}

int(*pmax)();
改成
int(*pmax)(int,int);

int(*pmax)();
跟int max(int ,int)不兼容;

改成
int(*pmax)(int,int);