fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. class header
  8. {
  9. public:
  10. virtual void func(void)=0;
  11. };
  12.  
  13. class func_1 : public header
  14. {
  15. public:
  16. virtual void func(void)
  17. {
  18. cout<<"func_1"<<endl;
  19. }
  20. };
  21.  
  22. class func_2 : public header
  23. {
  24. public:
  25. virtual void func(void)
  26. {
  27. cout<<"func_2"<<endl;
  28. }
  29. };
  30.  
  31. int main(void)
  32. {
  33. map<string,header*> func= {make_pair("func_1",new func_1()),
  34. make_pair("func_2",new func_2())
  35. };
  36.  
  37. func["func_1"]->func();
  38. func["func_2"]->func();
  39.  
  40. delete func["func_1"];
  41. delete func["func_2"];
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0s 2968KB
stdin
Standard input is empty
stdout
func_1
func_2