鱼C论坛

 找回密码
 立即注册
查看: 3709|回复: 4

指针调用函数问题 请大家帮忙看看

[复制链接]
发表于 2013-4-23 11:17:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
小甲鱼视频中的例子  用指针调用函数   编译出现下面的错误  不知道是不是代码也写错了 请大家帮忙看看
#include <stdio.h>

void main()
{
    int max(int,int);
    int min(int,int);
    int add(int,int);
   
    void process( int x,int y,int(*fun)() );
   
    int a,b;
   
    printf("Enter a and b: ");
    scanf("%d %d",&a,&b);
   
    printf("max = ");
    process(a,b,max);
   
    printf("min = ");
    process(a,b,min);
   
    printf("sum = ");
    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;
}



--------------------Configuration: test26 - Win32 Debug--------------------
Compiling...
test26.c
Linking...
test26.obj : error LNK2001: unresolved external symbol _process
Debug/test26.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

test26.exe - 2 error(s), 0 warning(s)


小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-4-23 12:10:00 | 显示全部楼层
process函数的定义呢???
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-4-23 12:46:03 | 显示全部楼层
void process( int x,int y,int(*fun)(int,int) );

int (*fun)(int,int)
fun 指针函数也要有参数
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2013-4-23 14:50:23 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2013-4-23 14:51:55 | 显示全部楼层
vfcv 发表于 2013-4-23 12:46
void process( int x,int y,int(*fun)(int,int) );

int (*fun)(int,int)

谢谢啊   不过在小甲鱼的视频中也是这么写的  应该是process函数这块有问题
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-8-1 18:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表