fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <memory>
  4.  
  5. using namespace std;
  6.  
  7. struct foo {
  8. virtual void print() { cout << "foo"; }
  9. };
  10.  
  11. struct bar : foo {
  12. virtual void print() { cout << "bar"; }
  13. };
  14.  
  15. int main()
  16. {
  17. map<int, shared_ptr<foo>> test = { {1, shared_ptr<foo>(new foo)}, {2, shared_ptr<foo>(new bar)} };
  18. test[2]->print();
  19. }
Success #stdin #stdout 0s 4140KB
stdin
Standard input is empty
stdout
bar