Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- class Derpbar {
- typedef void (*Handle)(const std::string&);
- typedef std::map<std::string, Handle> handleMap;
- public:
- void addHandle(const std::string& name, Handle func) {
- handles[name] = func;
- }
- void test(const std::string& name) {
- handles[name]("Works!");
- }
- private:
- handleMap handles;
- };
- void sth(const std::string& out) { std::cout<<out<<std::endl; }
- int main() {
- auto herp = new Derpbar();
- herp->addHandle("download", sth);
- herp->test("download");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement