|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
void main()
{
int max(int a,int b);
int min(int a,int b);
int add(int a,int b);
int process(int a,int b, int (*fun)());
int x,y;
printf("input two numbers:\n");
scanf("%d %d",&x,&y);
printf("max is:%d\n",process(x,y,max));
printf("min is:%d\n",process(x,y,min));
printf("add is:%d\n",process(x,y,add));
}
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}
int add(int a,int b)
{
return a+b;
}
int process(int a,int b, int (*fun)())
{
int z= (*fun)(a,b);
return z;
}
--------------------Configuration: 01 - Win32 Debug--------------------
Compiling...
01.cpp
d:\program files\microsoft visual studio\myprojects\20160608\01.cpp(15) : error C2664: 'process' : cannot convert parameter 3 from 'int (int,int)' to 'int (__cdecl *)(void)'
None of the functions with this name in scope match the target type
d:\program files\microsoft visual studio\myprojects\20160608\01.cpp(16) : error C2664: 'process' : cannot convert parameter 3 from 'int (int,int)' to 'int (__cdecl *)(void)'
None of the functions with this name in scope match the target type
d:\program files\microsoft visual studio\myprojects\20160608\01.cpp(17) : error C2664: 'process' : cannot convert parameter 3 from 'int (int,int)' to 'int (__cdecl *)(void)'
None of the functions with this name in scope match the target type
d:\program files\microsoft visual studio\myprojects\20160608\01.cpp(41) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
执行 cl.exe 时出错.
01.obj - 1 error(s), 0 warning(s)
|
|