lgy514

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include <iostream>
#include <thread>
#include <chrono>
#include <mutex>
#include <deque>
#include <map>
#include <condition_variable>
using namespace std;
typedef void(*fun)(char *) ;
class regist {
public:
    regist() {};
    void add(std::string key, fun f) {
        m[key] = f;
    };
    fun run(std::string key) {
        return m[key];
    }
private:
    std::map<std::string, fun > m;
};
void a(char *a) {
    cout << "a:" << a << endl;
}
void b(char *a) {
    cout <<"b:"<< a << endl;
}
int main() {
    regist reg;
    reg.add("a",a);
    reg.add("b", a);
    reg.run("b")((char *)"aaaa");
    reg.run("a")((char *)"bbbbb");
    return 0;
}

 

posted on 2020-07-18 01:28  lgy514  阅读(393)  评论(0编辑  收藏  举报