|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是程序:
#include <stdio.h>
void main()
{
int max(int, int);
int min(int, int);
int add(int, int);
void process(int, int, int(*fun)());
int a, b;
printf("Enter a and b: ");
scanf("%d %d", &a, &b);
printf("%d %d", a, b);
printf("max = ");
process(a, b, max);
printf("min = ");
process(a, b, min);
printf("add = ");
process(a, b, add);
}
int max(int x, int y)
{
int z;
if(x > y)
{
z = x;
}
else
{
z = y;
}
return z;
}
int min(int x, int y)
{
int z;
if(x < y)
{
z = x;
}
else
{
z = y;
}
return z;
}
int add(int x, int y)
{
int z;
z = x + y;
return z;
}
编译之后一直显示:
Linking...
zhixianghanshudezhizhen.obj : error LNK2001: unresolved external symbol _process
Debug/zhixianghanshudezhizhen.exe : fatal error LNK1120: 1 unresolved externals
求助各位大神,程序哪里错了,要怎么改?
你声明的这个函数void process(int, int, int(*fun)())都没有写实现,怎么可能不报错,还有 int(*fun)()这个回调函数调用的时候传的max、min、add都是调用的时候都是带两个参数的函数,而声明的时候确实无参的,应该改成这样的void process(int, int, int(*fun)(int, int)),最后完整的是这样,你试试... #include <stdio.h>
void main()
{
int max(int, int);
int min(int, int);
int add(int, int);
void process(int, int, int(*fun)(int, int));
int a, b;
printf("Enter a and b: ");
scanf("%d %d", &a, &b);
printf("%d %d", a, b);
printf("max = ");
process(a, b, max);
printf("min = ");
process(a, b, min);
printf("add = ");
process(a, b, add);
system("pause");
}
int max(int x, int y)
{
int z;
if (x > y)
{
z = x;
}
else
{
z = y;
}
return z;
}
int min(int x, int y)
{
int z;
if (x < y)
{
z = x;
}
else
{
z = y;
}
return z;
}
int add(int x, int y)
{
int z;
z = x + y;
return z;
}
void process(int a, int b, int(*myfun)(int, int))
{
printf("%d\n", myfun(a, b));
}
|
|