前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[C/C++]函数指针和函数分发表

[C/C++]函数指针和函数分发表

作者头像
静默虚空
发布2018-01-05 10:08:17
4110
发布2018-01-05 10:08:17
举报
文章被收录于专栏:静默虚空的博客
代码语言:javascript
复制
// console.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;

typedef unsigned char UCHAR;
int FunA();
int FunB();
int FunC();

typedef enum tagMsgType
{
    MSG_TYPE_A = 1,
    MSG_TYPE_B,
    MSG_TYPE_C
};

typedef int (*MSG_PROC_FUNC)();

typedef struct tagMsgDispatchTbl
{
    UCHAR ucMsgType;
    MSG_PROC_FUNC pFuc;
} MsgDispatchTbl;

MsgDispatchTbl g_astDispatchTbl[] = 
{
    {MSG_TYPE_A, FunA},
    {MSG_TYPE_B, FunB},
    {MSG_TYPE_C, FunC},
};

int FunA()
{
    printf("Call FunA\r\n");
    return 0;
}

int FunB()
{
    printf("Call FunB\r\n");
    return 0;
}

int FunC()
{
    printf("Call FunC\r\n");
    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    int i = 1;
    int iRet = 0;
    UCHAR ucMsgType = MSG_TYPE_B;
    UCHAR aucStr[1024] = {0};
    MSG_PROC_FUNC pFunc;
    for (i = 1; i < 4; i++)
    {
        if (ucMsgType == g_astDispatchTbl[i].ucMsgType)
        {
            pFunc = g_astDispatchTbl[i].pFuc;
            pFunc();
        }
        
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013-10-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档