Advertisement
WeltEnSTurm

Untitled

Dec 5th, 2011
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. class Derpbar {
  6.  
  7.         typedef void (*Handle)(const std::string&);
  8.         typedef std::map<std::string, Handle> handleMap;
  9.        
  10.     public:
  11.    
  12.         void addHandle(const std::string& name, Handle func) {
  13.             handles[name] = func;
  14.         }
  15.         void test(const std::string& name) {
  16.             handles[name]("Works!");
  17.         }
  18.        
  19.     private:
  20.    
  21.         handleMap handles;
  22. };
  23.  
  24. void sth(const std::string& out) { std::cout<<out<<std::endl; }
  25.  
  26. int main() {
  27.         auto herp = new Derpbar();
  28.         herp->addHandle("download", sth);
  29.         herp->test("download");
  30.         return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement