指针函数小用

#include "stdio.h"
typedef int (*FUN)(int x,int y);
FUN m_fun;
int add(int x,int y)
{
    return x+y;
}

int sub(int x,int y)
{
    return x-y;
}
enum method
{
    Add=1,
    Sub
};
void ChooseFun(method md,int x,int y)
{
    switch(md)
    {
    case Add:
        m_fun=add;
        break;
    case Sub:
        m_fun=sub;
        break;
    default:
        m_fun=add;
    }
    printf("X+Y=%d",m_fun(x,y));
}
int main()
{

    ChooseFun(Add,3,4);
    getchar();
}

 

posted on 2013-07-19 22:16  奔跑吧,蜗牛!  阅读(172)  评论(0编辑  收藏  举报

导航