fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Employee {};
  6. class A: public Employee {};
  7. class B: public Employee {};
  8. class C: public Employee {};
  9. typedef Employee *makeEmployee();
  10.  
  11. struct { string code; makeEmployee *maker; } Tb[]=
  12. {
  13. {"A",[]()->Employee*{ return new A(); }},
  14. {"B",[]()->Employee*{ return new B(); }},
  15. {"C",[]()->Employee*{ return new C(); }},
  16. };
  17.  
  18. int main()
  19. {
  20. Employee *obj=nullptr;
  21. string code="A";
  22. for(auto p:Tb) if(p.code==code) obj=p.maker();
  23. return 0;
  24. }
Success #stdin #stdout 0s 3452KB
stdin
Standard input is empty
stdout
Standard output is empty