#include <iostream>
#include <iterator>
#include <string>
#include <map>
using namespace std;
// 函数指针定义
typedef void (* switchcallback)(void);
void displayA() {
cout << "Aaaaa" << endl;
}
void displayB() {
cout << "Bbbbb" << endl;
}
void displayC() {
cout << "Ccccc" << endl;
}
int main() {
map <string,switchcallback> stringMap;
stringMap.insert(pair<string,switchcallback>("Aaaaa",displayA));
stringMap.insert(pair<string,switchcallback>("Bbbbb",displayB));
stringMap.insert(pair<string,switchcallback>("Ccccc",displayC));
map<string,switchcallback>::iterator stringMapItr;
stringMapItr = stringMap.find("Ccccc");
stringMapItr->second();
return 0;
}
用 Map 扩展switch
最新推荐文章于 2023-10-26 00:35:01 发布