fork(5) download
  1. #include <iostream>
  2. #include <memory>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. struct Base {
  8. virtual ~Base() {}
  9. virtual void method() = 0;
  10. };
  11.  
  12. struct Child : Base
  13. {
  14. void method() override { std::cout << "Child method" << std::endl; }
  15. };
  16.  
  17. int main() {
  18. map<string, unique_ptr<Base>> my_map;
  19.  
  20. my_map.insert(make_pair("Child1", unique_ptr<Base>(new Child)));
  21.  
  22. Base* ptr = my_map["Child1"].get();
  23. ptr->method();
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Child method