1 Star 1 Fork 1

无线电/3_c++练习

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
11_map_函数指针.cc 606 Bytes
一键复制 编辑 原始数据 按行查看 历史
#include <iostream>
#include <string>
#include <map>
using namespace std;
// 定义一个函数指针
typedef int (*handler_cmd_fun)(char* cmd);
int handler_wifi(char* cmd)
{
cout << "wifi:" << cmd << endl;
return 0;
}
int handler_version(char* cmd)
{
cout << "version:" << cmd << endl;
return 0;
}
int main(void)
{
map<string, handler_cmd_fun> cmd_fun;
cmd_fun["wifi"] = handler_wifi;
cmd_fun["version"] = handler_version;
char cmd[16] = "1234567";
for (auto it = cmd_fun.begin(); it != cmd_fun.end(); it++)
{
(*it).second(cmd);
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/zero2200/3_cpp-practice.git
git@gitee.com:zero2200/3_cpp-practice.git
zero2200
3_cpp-practice
3_c++练习
master

搜索帮助